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

后端 未结 11 1967
既然无缘
既然无缘 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:46

    Set AllowAllup to true, and Down to false.

    Then in OnClick event:

    ....
    btn.AllowAllUp := not btn.AllowAllUp;
    btn.Down       := not btn.Down;
    ....
    
    0 讨论(0)
  • 2021-01-04 12:47

    I have no D7 here, but in D2006 a Speedbutton stays down if the GroupIndex has a value > 0.

    If this is not the behaviour you wish, you can set the Down-Property manually in the OnClick-Eventhandler (make sure, that the GroupIndex is 0).

    0 讨论(0)
  • 2021-01-04 12:50

    Hm, strange, I remember using this quite a few times with success. Perhaps you should try playing with the SpeedButton's Down property? I don't think it toggles automatically when you click it --- you should explicitly toggle Down, I guess...

    [edit: replaced Checked with Down --- TSpeedButton doesn't have a Checked property, sorry!]

    0 讨论(0)
  • 2021-01-04 12:53

    GroupIndex groups the buttons. Only one buttons in the group may be active. All of them needs to have the same index higher than 0.

    AllowAllUp allows to switch button down and up, when it is clicked 2 times in a row.

    0 讨论(0)
  • 2021-01-04 12:55

    knight_killer is correct. i can tell you it'll work in any version of delphi:

    object SpeedButton1: TSpeedButton
      Left = 152
      Top = 384
      Width = 23
      Height = 22
      AllowAllUp = True
      GroupIndex = 99
    end
    
    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题