Overriding custom contol OnPaint
-
I am just starting to learn about creating custom controls using the book "GDI+ Custom Controls with Visual C# 2005". I am a little confused about overriding the control's OnPaint function. As a test, I created a custom control that has just a label. I then created the following code:
protected override void OnPaint(PaintEventArgs e)
{
// base.OnPaint(e);
}I figured that since I am not calling the base.OnPaint(e), that the label would not get displayed, however when I run this, the label still shows up. Can someone explain why overriding a custom control and not calling base.OnPaint(e) does not effect and controls that are part of the custom control?
-
I am just starting to learn about creating custom controls using the book "GDI+ Custom Controls with Visual C# 2005". I am a little confused about overriding the control's OnPaint function. As a test, I created a custom control that has just a label. I then created the following code:
protected override void OnPaint(PaintEventArgs e)
{
// base.OnPaint(e);
}I figured that since I am not calling the base.OnPaint(e), that the label would not get displayed, however when I run this, the label still shows up. Can someone explain why overriding a custom control and not calling base.OnPaint(e) does not effect and controls that are part of the custom control?
When you create a label control, a new window is created and as every window it's receiving it's own messages from the main message loop, including the paint message. A method
Label.OnPaint
is not invoked from theUserControl.OnPaint
. It's called byControl.WmPaint(ref Message m)
, which is called by (...), which is called byApplication.ThreadContext.RunMessageLoop(int reason, ApplicationContext context)
. Try to make a "user control", which derives fromLabel
, like this:class MyControl : Label
{
...
override OnPaint { }
}Then the label will not be drawn.
Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.