0

I've made my own custom ownerdrawn button control, inherited from the Button class itself. I draw the control all by myself in the OnPaint override procedure, this includes painting the background of the button, drawing its borders, text and image.

I also need to incorporate the capability for the button to show an Active color border in case the button has focus, or is defined as the AcceptButton by the parent form. For focus, I use this.ContainsFocus to know if the button currently has focus.

How to know if my button control is defined as the default AcceptButton on the parent form, so I can draw the active border color around it accordingly? I don't see any inherited property in the Button class to find this out.

Thanks.

Faraz Azhar
  • 562
  • 9
  • 28
  • The Parent Form knows and it calls the `NotifyDefault()` method when the AcceptButton is set. – Jimi Mar 14 '22 at 12:45
  • Your Button has a IsDefault Property that should reflect this. – Ralf Mar 14 '22 at 12:56
  • @Ralf That's what the (overridable) `NotifyDefault()` method sets :) (which in turn sets the [BS_DEFPUSHBUTTON](https://learn.microsoft.com/en-us/windows/win32/controls/button-styles) style) – Jimi Mar 14 '22 at 13:27
  • What I means is that, when custom-drawing a Button Control, you need to override `NotifyDefault()`, so the default style is not applied and you can replace it with your own designed *style*. A description here: [Flat Button Style - Hide border and Focus Cue when the Button is active](https://stackoverflow.com/a/64190445/7444103) – Jimi Mar 14 '22 at 14:04
  • Thanks @Jimi and Ralf. This solves my problem! :-) – Faraz Azhar Mar 14 '22 at 19:56

0 Answers0