Search code examples
windowslazarus

Lazarus button toggle mechanism


I wrote a little tool in Lazarus to use it as a launcher for some games of mine, all of this is done by cmd scripts which are linked to the press of a button.

Now I'm looking for two modifications to my tool, but since I'm not very talented when it comes to programming, I hope somebody can help me.

The first thing I'm looking for is to split the TButton caption into two lines. I have tried to do it over the GUI but did not find a solution for this.

The second thing I want to do is to change the caption and the function of a button by pressing on it. For example Button1 has the caption Enable Enhancements, which runs the script enhancements_on.bat. After I press the button, I want it to change the caption to Disable Enhancements, in order that the script enhancements_off.bat will run on next press.

Is this possible? if yes, how do you do it?


Solution

  • The first thing I'm looking for is to split the TButton caption into two lines.

    Simply set the caption of the Togglebox at runtime, e.g. in the OnCreate event of the form and use LineEnding to split the lines.

    Togglebox1.Caption := 'Line 1' + LineEnding + 'Line 2';
    

    Note that this works only with TTogglebox, not with TButton.