Subclassing Label, overidding OnPaint doesn't work?

  • Thread starter Thread starter Minerva Jones
  • Start date Start date
M

Minerva Jones

I'm using CF2.0 on WM5.

As in the subject, I need to create a Label with a tiny bit of extra
functionality. So I create a new user control, change :UserControl to
:Label and away I go. The thing is I need to override OnPaint, and
whilst it allows me to from a compiler POV (and just typing override
offers OnPaint as part of the list - so it's virtual), it doesn't get
called - ever.

Label is derived directly from Control, and if I switch to deriving
from Control myself, then OnPaint starts to get called! So how come it
doesn't when I'm derived from Label? Is Label doing something to block
my override, if so, how/what - and surely if it was sealed or not a
virtual method, the compiler would pick it up?

Incidentally, doing the exact same thing with a desktop project works
fine, OnPaint from a Label derived control always gets called.

Thanks for any help.
 
Your best option would be to create a class derived from UserControl or
Control and draw the text (and any custom stuff) yourself. Controls which
host the native windows controls are not as flexible in the Compact
Framework as the desktop and most do not let you create a graphics object to
do custom drawing.

Peter
 
Your best option would be to create a class derived from UserControl or
Control and draw the text (and any custom stuff) yourself. Controls which
host the native windows controls are not as flexible in the Compact
Framework as the desktop and most do not let you create a graphics object to
do custom drawing.

Thanks very much for this. I did try subclassing those two controls,
but they brought with them other problems meaning I had to implement
far more than I wanted to, just to re-implement the behaviour of
Label, before extending it to provide the small bit of extra behaviour
that I wanted. Since it would appear that I'll get nowhere with
subclassing Label, I guess I'll have to go down the other route!

Thanks for your help!
 
Back
Top