January 8th, 2012, 07:27 AM
[C#] Allow users to draw lines
How to allow users to draw lines as much as he wants
I made this. It draw just one line on specific coordinates. But I want to allow to draw as many lines as he wants, anywhere.
if radioButton1 is checked then I will be able to draw line, if radioButton2 is checked I will be able to draw something else
I'm learning C# and I want to learn that.
int x1, y1, x2, y2;
private void radioButton1_CheckedChanged(object sender, EventArgs e)
private void radioButton2_CheckedChanged(object sender, EventArgs e)
private void Form1_MouseDown(object sender, MouseEventArgs e)
x1 = e.X;
y1 = e.Y;
private void Form1_MouseUp(object sender, MouseEventArgs e)
x2 = e.X;
y2 = e.Y;
private void Form1_Paint(object sender, PaintEventArgs e)
objekt = this.CreateGraphics();
Pen olovka = new Pen(Color.Red, 5);
objekt.DrawLine(olovka, x1, y1, x2, y2);
Last edited by dada1; January 8th, 2012 at 12:48 PM.
February 14th, 2012, 03:09 PM
You can query the radio button on the mouse down event to figure out if the radio button is pressed.
In order to draw the line you probably want to save the first point when the mouse goes down and then the last point when the mouse goes up. Then draw when the mouse goes up.