0

hi everyone, i'm new in c# and events handling techniques, and i have a problem:

how can i call paint event inside of mouseclick event?

private void Form1_MouseClick(object sender, MouseEventArgs e)
{
Form1_Paint(?, ?);  //i need something like this...
}

i want to move rectangle(paint event moves it, right?) to place where mouse is clicked on the form.

4
Contributors
8
Replies
14
Views
6 Years
Discussion Span
Last Post by Acute
0

>how can i call paint event inside of mouseclick event?

You can handle all paint actions by getting/creating a reference of Graphics class.

Point oldp = new Point();
        Point newp = new Point();
        Graphics gc;
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            Graphics ps = this.CreateGraphics();
  
            oldp.X = newp.X;
            oldp.Y = newp.Y;
            newp = new Point(e.X, e.Y);
            
            ps.DrawLine(Pens.Red, newp, oldp);
        }
0

I've tried, but nothing happens when i click on the form...:( i don't know why, but drawing works only inside of Form1_Paint() event-method, WHY???

0

NO:( I've tried parentWindow_Panel2_Paint(null, null); and it seems to work but then after few seconds it gives error. Exception. I must give as a second argument PaintEventArgs, not null.....

0

Have you tried Control.Invalidate()? If all or part of a control is invalidated then a Paint event is raised.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.