Toggle button

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #35025
    JM-DG
    Participant

    Hi!

    I would like to know how to make a toggle button with a TsButton which would become:

    lighted up only if On

    else

    always normal state not lighted up Off.

    See attached image.

    Here's what I was able to do so far:

    Code:
    procedure TEq.OnOffbutClick(Sender: TObject);
    begin
    if OnOffbut.Caption = 'Off' then
    begin
    OnOffbut.Caption := 'On';
    // lighted up
    // I know it should be something like: EqOnOffbut.SkinData.SkinManager.???
    end
    else
    begin
    OnOffbut.Caption := 'Off';
    // not lighted up
    end;
    end;

    Thank you for your answers!

    #47660
    Support
    Keymaster

    Hello

    I have one idea only – painting of button as active manually in the OnPaint event…

    #47690
    JM-DG
    Participant

    Good idea. I'll let you know how it went. 🙂

    #47719
    JM-DG
    Participant

    Here's how I did it. 🙂

    Code:
    var EqIsOn: Boolean;

    procedure TEq.EqOnOffbutClick(Sender: TObject);
    begin
    if EqIsOn=true then
    begin
    EqIsOn:= false;
    EqOnOffbut.Caption := 'Off';
    end
    else
    begin
    EqIsOn:= true;
    EqOnOffbut.Caption := 'On';
    end;
    EqOnOffbut.Down:= EqIsOn;
    end;

    Thanks for the help!

    #47756
    Typograph
    Participant

    1. Put a SpeedButton on the form

    2. Set Property GroupIndex to a value higher than 0

    3. Set allowUp to TRUE

    In Code

    TsSpeedButton(Sander).Down := Not TsSpeedButton(Sander).Down

    #47757
    Typograph
    Participant

    procedure TEq.EqOnOffbutClick(Sender: TObject);

    Const

    Cap : array[0..1] Of String =('Off',On');

    begin

    TsSpeedButton(Sender).Down := Not TsSpeedButton(Sender).Down

    TsSpeedButton(Sender).Caption := Cap[TsSpeedButton(Sender).Down]

    end;

    Thats it….

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.