#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2007
    Posts
    84
    Rep Power
    7

    [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.

    Code:
     
            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)
              {
                  Graphics objekt;
                  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.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    144
    Rep Power
    17
    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.

IMN logo majestic logo threadwatch logo seochat tools logo