Graphics 101. Updating drawing.

  • Thread starter Thread starter Rob Brooks
  • Start date Start date
R

Rob Brooks

Hi,

I'm going some drawing via "Graphics" in a "Paint" callback and the commands
will only manifest themselves if I minimise the window and then maximise it
again.

I'm new to windows programming and so I am obviously missing a lot of the
basics when it comes to this sort of thing but my mandate is to get a
utility up and running ASAP.

What's the magic function call I'm missing?

Many thanks,

R.
private void PictureBox_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)

{

Graphics graphics = e.Graphics;

System.Drawing.Pen pen = new Pen( System.Drawing.Color.White );

graphics.DrawPath( pen, graphicsPath1 );

}
 
Rob,

Paint event will only be fired when there's the need to paint something.
That is why you must minimize your window in order to see your code work.

Whenever you want a piece of a control / form to be painted, you should call
Invalidate on that control / form. You can optionally pass the area to
invalidate as an argument to Invalidate.

The Paint event won't be fired immediately; it will be fired when your
application has no other events to process. You can force a control to
repaint itself by calling Refresh, but it is better waiting for the system
to do it automatically.

You can optimize your Paint logic if you look at the Clip rectangle passed
to you. It tells you which part of the control needs being repainted.

Hope it helps
 
Cool. Thanks for that.

I was able to Invalidate my PictureBox in the Form by passing just a
Rectangle to the Invalidate member function of the PictureBox.

I seemed to be the best version to use use as I was merely plotting a
control point cursor on the picturebox with a mouse click.

Nice and efficient.

Thanks again.

R.
 
Back
Top