Button control

Topics: Developer Forum
Apr 12, 2008 at 11:53 PM
Edited Apr 12, 2008 at 11:58 PM
Current button control has several problems. First the easy ones:

- leakes an HICON each time the Image property is set
- will crash on x64 since the HICON is truncated to 32-bits in SendMessage(BM_SETIMAGE)

The bigger problem is we really can't reliably support images in this manner. There's no OnImageChanged method to override. And the hiding behavior means an AeroButton works only when accessed through an AeroButton refrence, and does not when accessed through a Button or ButtonBase reference. Clearly very very bad.

I propose the following solution: AeroButton would use FlatStyle.Standard by default, and would have a property called RequiresElevation, which would switch it to FlatStyle.System and send a BCM_SETSHIELD when true. This would mean the control would behave just like standard button all the time (with Images, ImageLists, image-text alignment, and all that stuff), and only when RequiresElevation was true, it would display the shield (and no other icon. Which is quite reasonable, I think).

Apr 13, 2008 at 12:10 AM
One problem is that the FlatStyle.System supports animations, unlike the .net Standard style. I'm afraid we're going to have to choose between images and animations. I'd go for animations, because they are part of the Aero style, whereas various images other than the shield are not. And anyone who wants images is free to use standard Button, after all.
Apr 13, 2008 at 10:52 PM
It gets much worse with the CommandLink control, which definitely needs to support images. I'm currently leaning to an implementation not derived from a Button. That is, let's write a custom AeroButtonBase, which will do pretty much everything S.W.F.ButtonBase does, and derive AeroButton and AeroCommandLink from it. It's gonna be a lot of work, no doubt.

To allow shield icons on standard controls, we can make an ElevationRequiredProvider component (an IExtenderProvider), which will provide an ElevationRequired property for standard buttons, menus and menu strip items (something else, maybe?)