I am trying to have the program draw on the form itself, where the user clicks and holds the mouse down (mouseevent) then the user moves the mouse to any spot on the form and does mouse up (or releases the left mouse button) and it draws a blue line from mouse down to mouse up, i have the code below, looks like it works, but when i run it and try it, its not, it just has all the points 0,0,0,0 but here is the code below, hope this makes sense what i want to do, this is for training on gui interfaces etc. but i am learning C# networking with this.
thanks in advance:
public int mouseupx = 0, mouseupy = 0, mousedownx = 0, mousedowny = 0;
public Point location1 = new Point();
public Point location2 = new Point();
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mousedownx = location1.X;
mousedowny = location1.Y;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
Graphics surface;
Pen pen = new Pen(Color.Blue, 2.0f);
surface = this.CreateGraphics();
mouseupx = location2.X;
mouseupy = location2.Y;
surface.DrawLine(pen, mousedownx, mousedowny, mouseupx, mouseupy);
}


Sign In
Create Account


Back to top









