Control Painting

Peter Osucha <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <[email protected]>
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.