CustomControl.Paint Not Firing
-
Hi I've created a Custom Control "YoLabel" with
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
and drawing it inside OnPaint(...) method. The Control draws itself fine. Now I need to paint something more from outside the label such asYoLabel lbl = new YoLabel(); lbl.Paint += delegate(object s, PaintEventArgs) { // My Painting logic };
Now the above Event Handler is not firing. Inside YoLabel Control I'm using invalidate whenever Text, Color, etc properties are changed to repaint it. So what is missing. Please Advice. Thanks... -
Hi I've created a Custom Control "YoLabel" with
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
and drawing it inside OnPaint(...) method. The Control draws itself fine. Now I need to paint something more from outside the label such asYoLabel lbl = new YoLabel(); lbl.Paint += delegate(object s, PaintEventArgs) { // My Painting logic };
Now the above Event Handler is not firing. Inside YoLabel Control I'm using invalidate whenever Text, Color, etc properties are changed to repaint it. So what is missing. Please Advice. Thanks... -
do you call base.OnPaint in your override of OnPaint? the Paint - Event is fired from there.
Thanks m@u it worked fine...
-
Hi I've created a Custom Control "YoLabel" with
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
and drawing it inside OnPaint(...) method. The Control draws itself fine. Now I need to paint something more from outside the label such asYoLabel lbl = new YoLabel(); lbl.Paint += delegate(object s, PaintEventArgs) { // My Painting logic };
Now the above Event Handler is not firing. Inside YoLabel Control I'm using invalidate whenever Text, Color, etc properties are changed to repaint it. So what is missing. Please Advice. Thanks...Hi,
Sukhjinder_K wrote:
YoLabel lbl = new YoLabel(); lbl.Paint += delegate(object s, PaintEventArgs
it seems like you have two YoLabels now, one got added to Form.Controls and paints fine thru OnPaint, the second one is not part of any Control collection, hence will never become visible or get its Paint event fired. You should not create a second YoLabel, you should add your painting delegate to the Paint event of the existing YoLabel. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
-
Hi,
Sukhjinder_K wrote:
YoLabel lbl = new YoLabel(); lbl.Paint += delegate(object s, PaintEventArgs
it seems like you have two YoLabels now, one got added to Form.Controls and paints fine thru OnPaint, the second one is not part of any Control collection, hence will never become visible or get its Paint event fired. You should not create a second YoLabel, you should add your painting delegate to the Paint event of the existing YoLabel. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
Thanks for the interest codeproject. I'm creating a YoLabel as
MyForm : Form { MyForm() { YoLabel lbl = new YoLabel(); lbl.Paint += delegate(...); //I can have another event delegate as lbl.MouseUp += delegate(...) this.Controls.Add(lbl); this.lbl.BringToFront();//I need to do this to show it on top of another control } }
So I have only one YoLabel... -
Thanks for the interest codeproject. I'm creating a YoLabel as
MyForm : Form { MyForm() { YoLabel lbl = new YoLabel(); lbl.Paint += delegate(...); //I can have another event delegate as lbl.MouseUp += delegate(...) this.Controls.Add(lbl); this.lbl.BringToFront();//I need to do this to show it on top of another control } }
So I have only one YoLabel...then all is fine, as long as you call base.OnPaint() as the other reply mentioned. some people by mistake create a new instance to invoke a method or add a delegate, which obviously does not produce the result they are after. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets