How to make a Delphi TSpeedButton stay pressed if it's the only one in the group

后端 未结 11 1968
既然无缘
既然无缘 2021-01-04 12:13

I\'m not sure why the TSpeedButton has this property but when a TSpeedButton is the only button of a given groupindex, it doesn\'t stay pressed, whether or not \"AllowAllUp\

11条回答
  •  抹茶落季
    2021-01-04 12:55

    I was searching for a solution for my problem and I think this is kind of the same one. I wanted to make a SpeedButton toggle the up and down state just like a switch, and I managed this by setting the properties:

    AllowAllUp := True; 
    GroupIndex := 1;
    

    Then in the OnClick event of the button I wrote:

    procedure TForm1.SpeedButton1Click(Sender: TObject);
    begin
      if( SpeedButton1.AllowAllUp ) then 
      begin 
        SpeedButton1.AllowAllUp := False; 
        SpeedButton1.Down := True; 
      end else 
      begin 
        SpeedButton1.AllowAllUp := True; 
        SpeedButton1.Down := False; 
      end; 
    end;
    

    This toggles the button down when it's clicked and up when it's clicked again.

    Hope it'll be of any help

提交回复
热议问题