问题
TButton in Delphi XE2 has a Style
property. When this property is set to bsSplitButton
then a drop-down arrow is displayed on the right side of the button:
However, this drop-down area has some inconveniences:
In many cases it is too narrow, the static width of the drop-down area is only 11 pixels.
There is no explicit hover indication just for the drop-down area when the mouse pointer hovers over the drop-down area.
How can a descendant of TButton be implemented which repairs this inconveniences? The descendant should have a DropDownWidth
property and a property which handles and changes the drop-down display when the mouse hovers over the drop-down area.
回答1:
Your descendant must call Button_SplitInfo
(or send BCM_SETSPLITINFO
) to adjust the split width. Below is a run-time example usage, you can integrate similar functionality in your descendant:
procedure SetButtonSplitWidth(Button: TButton; Width: Integer);
var
Info: TButtonSplitinfo;
begin
if Button.Style = bsSplitButton then begin
Info.mask := BCSIF_SIZE;
Info.size.cx := Width;
Info.size.cy := 0;
Button_SetSplitInfo(Button.Handle, Info);
Button.Invalidate;
end;
end;
Sample result with the call
SetButtonSplitWidth(Button2, 25);
is like this:
See documentation for what else you can do. There's no functionality that modifies the hovering behavior for a native button control. For that, you would probably better not start from a TButton
.
来源:https://stackoverflow.com/questions/24288185/tbutton-deficiencies