Design-time updating of UserControl

M

Michael Chapman

I have a UserControl-derived class that behaves somewhat strangely in
the form designer. Some properties (BorderStyle and Font) cause the
control to be updated in the designer, but others (ForeColor and
BackColor) do not. I've overriden OnBackColorChanged and also tried
adding an EventHandler for BackColorChanged. Neither seemed to have
any effect. At run-time the colors are correct. Any advice is greatly
appreciated. Do I need to modify my ControlDesigner class? Do I need to
add some design-time attribute to my member functions?

Thanks,

Michael
 
M

MuZZy

Michael said:
I have a UserControl-derived class that behaves somewhat strangely in
the form designer. Some properties (BorderStyle and Font) cause the
control to be updated in the designer, but others (ForeColor and
BackColor) do not. I've overriden OnBackColorChanged and also tried
adding an EventHandler for BackColorChanged. Neither seemed to have
any effect. At run-time the colors are correct. Any advice is greatly
appreciated. Do I need to modify my ControlDesigner class? Do I need to
add some design-time attribute to my member functions?

Thanks,

Michael


Hi Michael,

Just a comment: in the UserControl itself you should never override OnXxxxx functions.
Instead you should add event handler for Xxxxx functions, e.g instead of ooverriding OnPaint
you should add an EH to Paint.

So try just to add an event handler for BackColorChanged and don't remove your OnBackColorChanged implementation.


Andrey
 
M

Michael Chapman

I have both an override of OnBackColorChanged and an event handler for
BackColorChanged. I still get no effect in design mode, but correct
color at run-time.

Also, why should OnXxxx() functions not be overriden? Not that I don't
believe you, but I haven't heard that before.
 
M

MuZZy

Hm, i just created a test solution with a UserControl project and a WinForms application
I placed my usercontrol on the form and i can do whatever updates designer shows in UC properties.

Andrey
 
M

Michael Chapman

Thanks for looking at this. I just made a new solution with a new
Windows Control Library project. I dropped in the same UserControl
files I had from the previous project. Now, it works fine.
 
M

MuZZy

Michael said:
I have both an override of OnBackColorChanged and an event handler for
BackColorChanged. I still get no effect in design mode, but correct
color at run-time.

Also, why should OnXxxx() functions not be overriden? Not that I don't
believe you, but I haven't heard that before.

I'm really sorry Mike, i mixed those two - you SHOULD override OnEvent...
Say, if you want your UserControl to draw a rectangle by default, you should put all the drawing stuff in
overriden OnPaint method of usercontrol

Sorry for misinforming you!

Andrey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top