Re: Control Painting

Peter Osucha <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <00bf01c79cc5$da964500$0202a8c0@peterhome>
Thanks, Chris.  I'll give it a whirl this evening and see what happens.

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
>
>
>
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.