Clicking a button from windows form it doesn't work.
Because, I have to use the parameters "Graphics g..." for the methods. I can't change the methods so, I have to change something when the user clicks the button.
Below is the code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//protected override void OnPaint(PaintEventArgs e)
//{
// Graphics g = e.Graphics;
// TekenCirkel(g, 50, 50, 100, 100);
// TekenRechthoek(g, 0, 0, 100, 100);
//}
public void TekenCirkel(Graphics g, int x, int y, int w, int h) {
Pen cirkel = new Pen(Color.Blue, 2);
g.DrawEllipse(cirkel, x,y, w, h);
}
public void TekenRechthoek(Graphics g, int x, int y, int w, int h){
Pen rechthoek = new Pen(Color.Black, 2);
g.DrawRectangle(rechthoek, x, y, w, h);
}
private void Cirkel_Click(object sender, EventArgs e)
{
TekenCirkel(g, 50, 50, 100, 100);
}
}
As you can see I tested it with the onPaint method and defining what g does. When using this method the code works. But that isn't possible when trying to click the button. Because EventArgs and PaintEventArgs are different things.
E: You click a button and a cirkel/square gets painted on the form. I want to know how to call a method I created to draw the cirkel/ square.