TButton deficiencies

醉酒当歌 提交于 2019-12-10 10:37:19

问题


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:

  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:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!