Hello. I need to help becuase I'm really desperate :( :) ..... I'm trying to program the program just same like the drawing software in the window 7, but not completely same xD xD. Unfortunately I have a problem with drawlines....I can't do that. I want to draw line by mouse by e.X and e.Y. I know I should list<Point> but I don't know how to do that. I'm sending some code what I devised.
Somebody to helped me that I should use drawlines and don't use Fillellipse. :( Please, somebody to help me. I'll be very glad.

private void panel1_MouseMove(object sender, MouseEventArgs e)
            {

                if (action2)
                {
                    stetec = new SolidBrush(lbl_color.BackColor);
                    Graphics kp = panel1.CreateGraphics();
                    kp.FillEllipse(stetec, e.X, e.Y, 14, 14);
                    kp.Dispose();
                }
            }

    private void panel1_MouseUp(object sender, MouseEventArgs e)
            {
                action2 = false;

             
            }

    private void panel1_MouseDown(object sender, MouseEventArgs e)
            {
                action2 = true;
            }

    private void panel1_Paint(object sender, PaintEventArgs e)
            {
               
               
            }

This code draws line on mouse move

protected override void OnMouseMove(MouseEventArgs mouseEv)

        { int mouseX = mouseEv.X;
            int mouseY = mouseEv.Y;
            // Create new graphics object
            Graphics gfx = CreateGraphics();
            // Create a pen that has the same background color as the form
            Pen erasePen = new Pen(Color.White);
            // Draw a line that will erase the previous line created
            gfx.DrawLine(erasePen, 0, 0, mouseX, mouseY);
            // Create a pen that will draw the blue line
            Pen linePen = new Pen(Color.Blue);
            gfx.DrawLine(linePen, 0, 0, mouseX, mouseY);
        }

Edited 5 Years Ago by abelLazm: n/a

Hi, thank you so much for your code but it's by OnMouseMove...But I can't do that...I can only by Mouse_move....Is it the same ?

use this code like this

void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            this.OnMouseMove(e);
        }
        protected override void OnMouseMove(MouseEventArgs mouseEv)
        {
            int mouseX = mouseEv.X;
            int mouseY = mouseEv.Y;
            // Create new graphics object
            Graphics gfx = CreateGraphics();
            // Create a pen that has the same background color as the form
            Pen erasePen = new Pen(Color.White);
            // Draw a line that will erase the previous line created
            gfx.DrawLine(erasePen, 0, 0, mouseX, mouseY);
            // Create a pen that will draw the blue line
            Pen linePen = new Pen(Color.Blue);
            gfx.DrawLine(linePen, 0, 0, mouseX, mouseY);
        }

and stop drawing line on mouse_up event

This article has been dead for over six months. Start a new discussion instead.