Custom button from a Control class doesn't appear as a choice for OK/Cancel button in a Form propert

  • Thread starter Thread starter CroDude
  • Start date Start date
C

CroDude

Hi all!
I've made a button from scratch derived from a Control class. The main
reason why Control and not Button class is used for inheritance is that when
deriving from a control class it's possible to have a transparent
background, while if derived from a button class it isn't.
That's achieved through:
SetStyle(ControlStyles.SupportsTransparentBackColor, true);

But the problem appears when I place my buttons on a form and try to set
them as a OK/Cancel buttons. It seems that a form can't recognize my buttons
when I want to choose them as OK/Cancel button of a Form.
Is there something that I'm missing? Please help!

Thanks in advance!
Dinko Pavicic
 
It is possible to have transparency when inheriting from the button class.
As well as setting SupportsTransparentBackColor to true you must set Opaque
to False.

I wrote a button inherited from button a while back and posted the code on
my site.
http://dotnetrix.co.uk/buttons.html
There were a few obstacles to overcome so you may like to just borrow the
code and provide your own paint methods, but as Tim said, Implementing
IButtonControl on your current control should do the trick.
 
Back
Top