Re: Control Painting
Peter Osucha <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <[email protected]> |
OK, Chris, let me ask about the second comment first...
My OnPaint() event handler is what is calling DrawFigure();
private void OnPaint ( object sender, PaintEventArgs e )
{
// Draw the wells and well headers and cartridge border.
DrawFigure ( );
}
So I can't just invalidate the canvas in the DrawFigure() method -
nothing will be drawn. However, you're note to Steve Savage on VISBASL
might be useful for my understanding.
The 'OnPaint()' event fires whenever the form (control, etc.) needs to
have its graphic area refreshed. So I need to do all my drawing of
persistent graphics in this event handler, correct?
Also, If my class is hooked into and handling this event, when does the
hosting control (the panel or the ultraGroupBox) do the rest of its
painting (after or before mine)? It seems that on the initial panel
object I was using, no painting was done after I did my drawing. On the
groupbox, it seems that additional painting is done after mine since my
graphic is overwritten with a blank area.
Peter
-----Original Message-----
From: Discussion forum for developers using Windows Forms to build apps
and controls [mailto:[email protected]] On Behalf Of
Chris Anderson
Sent: Tuesday, May 22, 2007 5:55 PM
To: [email protected]
Subject: Re: [DOTNET-WINFORMS] Control Painting
The Paint event will send you a Graphics object - you should use that to
paint your figure rather than create a new one
Also public void DrawFigure should only invalidate the canvas.
This will cause a Paint event to fire, and it's in there that you should
use the passed in Graphics object to paint to.
> -----Original Message-----
> From: Discussion forum for developers using Windows Forms to build
apps
> and controls [mailto:[email protected]] On Behalf Of
> Peter Osucha
> Sent: 22 May 2007 22:16
> To: [email protected]
> Subject: [DOTNET-WINFORMS] Control Painting
>
> One more for you gentlemen (and ladies)...
>
>
>
> I have a class that accepts a 'canvas' in its constructor (a reference
> which is held in the class with the variable '_canvas'). The canvas
is
> any control that has a Graphics object that can be drawn to (normally,
> I
> use a System.Windows.Forms.Panel object that is placed on a form).
>
>
>
> The main method in this class is called 'DrawFigure' and it is
intended
> to do all the drawing of the 'Figure' the class is working with.
>
>
>
> I have added several event handlers to the class - probably most
> importantly is a handler for the _canvas.Paint event. And this is
> where
> I lose a bit of understanding.
>
>
>
> In the event handler I have hooked to _canvas.Paint, I call the
> 'DrawFigure'method - I don't do anything else.
>
>
>
> The 'DrawFigure' method looks like...
>
>
>
> public void DrawFigure()
>
> {
>
>
>
> _canvas.SuspendLayout ( );
>
>
>
> Graphics g = Graphics.FromHwnd ( _canvas.Handle );
>
>
>
> g.Clear ( _canvas.BackColor);
>
> g.TextRenderingHint =
> System.Drawing.Text.TextRenderingHint.AntiAlias;
>
> g.TextContrast = 12;
>
>
>
> // blah, blah, blah code to draw what I want...
>
>
>
> _canvas.ResumeLayout ( );
>
>
>
> // Always dispose fo the Graphics object.
>
> g.Dispose ( );
>
> }
>
>
>
> Now to my question... I want to use another control for the canvas
> (FWIW, it's a Infragistics.UltraGroupBox - not that that should
> necessarily matter). However, I must be doing something screwy with
> the
> painting since my drawing doesn't show up on this new 'canvas' until I
> click on a part of it (and then only part of drawing shows).
>
>
>
> I don't understand the event chain that is going on and what and when
I
> should probably be painting. Any suggestions about where to look get
> my
> class drawing correctly on this new 'canvas'?
>
>
>
> Peter
>
>
>
>
>