views:

23

answers:

1

I'm creating a base class for a button that inherits from Control as opposed to ButtonBase.
I'm using reflector to look at ButtonBase to make sure I don't overlook anything important and I'm puzzled with the contents of the WndProc method.
There's checks in there for things like button up, click and capture changed, which as far as I can tell are all handled within the relevent 'On' methods of the class.

Does anyone know why they are in there?

+1  A: 

It is a wrapper for the native Windows button control as well. In a nutshell:

  • 0x00f5 = BM_CLICK: run OnClick()
  • 0x2111 = BN_CLICKED notification : run OnClick()
  • a bunch of workarounds to deal with OwnerDraw.

You don't have to worry about any of this since you don't wrap a native button and don't need owner draw. Do make sure you implement IButtonControl so your button behaves properly when Enter and Escape is pressed and it is selected as the form's Accept/CancelButton. Not strictly necessary, but it is automatic when you inherit from ButtonBase instead of Control.

Hans Passant
Thanks, that makes sense now.
Jules