如何按下多个 TSpeedButtons?
How to have multiple TSpeedButtons down?
我正在尝试在 TFlowPanel 上使用多个 TSpeedButton 来显示用户可以选择的选项列表。这就是我创建这些按钮的方式:
procedure FillOptions(ButtonPanel: TFlowPanel; Options: TStrings; Action: TNotifyEvent);
var Option: string;
Button: TSpeedButton;
begin
for Option in Options do begin
Button:= TSpeedButton.Create(ButtonPanel);
Button.Caption := Option;
Button.Width := Canvas.TextWidth(Option) + 20;
Button.GroupIndex := 99;
Button.AllowAllUp := True;
Button.OnClick := Action;
Button.Parent := ButtonPanel;
end;
end;
问题是我无法选择多个选项。当我单击一个按钮时,它会下降,但之前选择的按钮会上升。
我忘记设置什么了,所以可以同时按下一个以上的按钮?
谢谢。
TSpeedButton.GroupIndex
上的文档充分解释了这一点(强调我的):
When GroupIndex is 0, the button behaves independently of all other buttons on the form. When the user clicks such a speed button, the button appears pressed (in its clicked state) and then returns to its normal up state when the user releases the mouse button.
When GroupIndex is greater than 0, the button remains selected (in its down state) when clicked by the user. When the user clicks a selected button, it returns to the up state, unless AllowAllUp is false. Setting the GroupIndex property of a single speed button to a value greater than 0 causes the button to behave as a two-state button when AllowAllUp is true.
Speed buttons with the same GroupIndex property value (other than 0) work together as a group. When the user clicks one of these buttons, it remains selected until the user clicks another speed button belonging to the same group. Speed buttons used in this way can present mutually exclusive choices to the user.
换句话说,这就是速度按钮的工作原理。如果五个速度按钮属于同一组,至多在任何给定时间点可以选择(向下)其中一个。
AllowAllUp
属性 仅仅可以选择 zero 按钮(向下);没有办法同时关闭 多个 ,除非它们具有不同的 GroupIndex
.
值
因此,您需要为每个按钮指定非零值 GroupIndex
,并确保它们都有 AllowAllUp = True
。然后每个按钮将单独切换。
我正在尝试在 TFlowPanel 上使用多个 TSpeedButton 来显示用户可以选择的选项列表。这就是我创建这些按钮的方式:
procedure FillOptions(ButtonPanel: TFlowPanel; Options: TStrings; Action: TNotifyEvent);
var Option: string;
Button: TSpeedButton;
begin
for Option in Options do begin
Button:= TSpeedButton.Create(ButtonPanel);
Button.Caption := Option;
Button.Width := Canvas.TextWidth(Option) + 20;
Button.GroupIndex := 99;
Button.AllowAllUp := True;
Button.OnClick := Action;
Button.Parent := ButtonPanel;
end;
end;
问题是我无法选择多个选项。当我单击一个按钮时,它会下降,但之前选择的按钮会上升。
我忘记设置什么了,所以可以同时按下一个以上的按钮?
谢谢。
TSpeedButton.GroupIndex
上的文档充分解释了这一点(强调我的):
When GroupIndex is 0, the button behaves independently of all other buttons on the form. When the user clicks such a speed button, the button appears pressed (in its clicked state) and then returns to its normal up state when the user releases the mouse button.
When GroupIndex is greater than 0, the button remains selected (in its down state) when clicked by the user. When the user clicks a selected button, it returns to the up state, unless AllowAllUp is false. Setting the GroupIndex property of a single speed button to a value greater than 0 causes the button to behave as a two-state button when AllowAllUp is true.
Speed buttons with the same GroupIndex property value (other than 0) work together as a group. When the user clicks one of these buttons, it remains selected until the user clicks another speed button belonging to the same group. Speed buttons used in this way can present mutually exclusive choices to the user.
换句话说,这就是速度按钮的工作原理。如果五个速度按钮属于同一组,至多在任何给定时间点可以选择(向下)其中一个。
AllowAllUp
属性 仅仅可以选择 zero 按钮(向下);没有办法同时关闭 多个 ,除非它们具有不同的 GroupIndex
.
因此,您需要为每个按钮指定非零值 GroupIndex
,并确保它们都有 AllowAllUp = True
。然后每个按钮将单独切换。