2

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:

enter image description here

However, this drop-down area has some inconveniences:

  1. In many cases it is too narrow, the static width of the drop-down area is only 11 pixels.

  2. 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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
user1580348
  • 5,721
  • 4
  • 43
  • 105
  • How can it be implemented? Well, fire up the editor and write the code. You really need to ask a more specific question if you want specific help. – David Heffernan Jun 23 '14 at 14:51

1 Answers1

12

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:

enter image description here

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.

Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169