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.

1
  • 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. Jun 23, 2014 at 14:51

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.