On 2007-11-30 12:03:35 -0800, Slickuser <(E-Mail Removed)> said:
> If I use that way, I need some how to pass in a PaintEvents to draw.
No, you don't. Windows generates the PaintEventArgs. You don't call
OnPaint() yourself, and you don't raise the Paint event yourself. You
use Control.Invalidate() to tell Windows what area of the control needs
to be redrawn, and Windows handles the rest.
> That how why I choose doing this way.
You are doing it wrong. You will continue to have problems as long as
you continue to do it wrong.
You can find a discussion on proper techniques for custom drawing in .NET here:
http://msdn2.microsoft.com/en-us/library/kxys6ytf.aspx
While it focuses on an actual custom control, the concepts are the same
whether you are overriding OnPaint() or just handling the Paint event
of a Control instance.
You may also want to learn more about the underlying Windows drawing
model, which is documented here
http://msdn2.microsoft.com/en-us/library/ms534857.aspx
Note that this model is not unique to Windows. It's a common paradigm,
and so if you learn how to do it in Windows, you will be familiar with
drawing in many different GUI platforms. More importantly, because its
close relationship with the basic .NET drawing model, learning about
the unmanaged Windows paradigm will actually help you understand the
..NET model better as well.
Finally, you may want to consider learning about the Windows
Presentation Foundation (WPF). While I don't know much about it
myself, my understanding is that it's a more declarative paradigm, as
opposed to the event-driven paradigm you're trying to use in a sort of
declarative way.
http://msdn2.microsoft.com/en-us/library/ms754130.aspx
Pete