From Clomosy Docs

No edit summary
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
A ''TclButton'' is a general-purpose push button for use in applications. When the button is clicked, we can navigate to a function, procedure or activate other actions.<br>
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
function AddNewButton(AComponent: TCLComponent; xName, xCaption: string): TclButton;
</div>


AddNewButton (TComponent, xName, xCaption): TClButton
<span style="color:blue"><b>AComponent</b></span> : Specifies the parent of the object to be defined.<br>


<span style="color:blue">''TComponent''</span> : The variable name of the defined component is written. Here you should write the component variable name of whatever your component will be in.
<span style="color:blue"><b>xName</b></span> : The name of the defined button should be written.<br>


<span style="color:blue">''xName''</span> : The name of the defined button should be written.
<span style="color:blue"><b>xCaption</b></span> : You can add a title.<br>


<span style="color:blue">''xCaption''</span> : You can add a title.
It is a component used to perform a specific action in the user interface. When a button is placed on the form, it allows the user to trigger a particular function by clicking it. For example, a "Save" button can be added to allow data to be saved.<br>


Let's create a button.<br>
<div class="table-responsive">
{| class="wikitable" style="border: 2px solid #c3d7e0"
! style="background-color: #c3d7e0"| Feature  !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"| Definition
|-
|TClButton || Button1 : TclButton;  || A variable belonging to the TclButton class is created.
|-
|AddNewButton || Button1 = Form1.AddNewButton(Form1,'Button1','Test Button Caption'); || A new TclButton is added to the form.
|-
|Width || Button1.Width = 150; ||Allows adjusting the width of the button.
|-
|Height || Button1.Height = 50; ||Allows adjusting the height of the button.
|-
|Align  || Button1.Align = alTop; ||With the Align parameter, you can specify where you want our component to be aligned in the form. This parameter has multiple positioning properties. See the [[Object_Properties#Align | page]] to learn about these features.
|-
|Margins || Button1.Margins.Left = 50; // Right, Top, Bottom ||With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.<br>[[File:TclButtonMargins.png|frameless|200px]]<br><br>
|-
|Caption || Button1.Caption = 'Button Caption'; || It represents the text displayed on the component. The Caption specifies the textual label that the component presents to the user.
|-
|Text || Button1.Text = 'Button's Text'; || It represents the text within the component. The text entered by the user or set by the program is managed through this property.
|-
|TextSettings || Button1.StyledSettings = ssFamily;<br><br>Button1.TextSettings.FontColor = clAlphaColor.clHexToColor('#8a067c');<br><br>Button1.TextSettings.Font.Size = 20;<br><br>Button1.TextSettings.Font.Style = [fsItalic]; //[fsItalic,fsUnderline] || Text formatting is performed in the component. To see the usage, see [https://www.docs.clomosy.com/index.php/Object_Properties#Text_Settings page].
|}
</div>


1. Create a new project.<br>


2. You need to define TclButton on the form. To do this, you should add under the ''var'' parameter on the ide as follows. It is the name of your variable you typed at the beginning. You should define this as you want and add it as TclButton.<br>
<b>Example</b><br>
'''var'''
<pre>
testButton : TclButton;
var
 
  MyForm:TclForm;
3. Add the TclButton to the form. For this, you must add the begin end block and add it inside the form after the form is defined. By saying MyForm.AddNewButton, we actually add to the form we have defined. Here, you need to add your form definition as whatever you wrote it.<br>
  testButton : TclButton;
 
testButton:= ''MyForm''.AddNewButton(MyForm,'testButton','Test Button Caption');
 
4. If you do not want to define it in the form, you can add it in another component (such as Layout, Panel). Of course, before that, that component must be defined.
<span style="color:blue">testLayout</span> := MyForm.AddNewLayout(MyForm,'testLayout');
testButton:= MyForm.AddNewButton(<span style="color:blue">testLayout</span>,'testButton','Test Button Caption');
 
5. While defining the component, you can define it manually by typing. Another method is to write its shortcut. If you type "AddNewButton" while the shortcut is in the code block, a pop-up menu will appear.<br>
[[File:TclButtonShourtcut.png|frameless|400px]]<br><br>
 
As soon as you click, the following block will come automatically.<br>
 
AddNewButton(xOwner:TComponent; xName,xCaption:String);
 
6. We gave the variable name while defining the TclButton in var. Now when you add this in begin end you should use this variable name in all definitions. Your code will throw an error when you write these variable names incorrectly.
 
7. You give a title to your Button component as the last parameter when defining your project. This title is the text that will appear on the screen when the application is run. You may not want to write this title while defining it.
   
   
  testButton:= ''MyForm''.AddNewButton(MyForm,'testButton',<nowiki>''</nowiki>);
  {
 
  MyForm = TclForm.Create(Self);
8. Then you can make a definition as follows. Well, an external title can be entered so that it does not appear empty when this project is run. For this, a title can be added with label.Caption assignment.
  testButton= MyForm.AddNewButton(MyForm,'testButton','Click');
  testButton.TextSettings.Font.Size=50;
  testButton.Align = alCenter;
  testButton.Height = 50;
  testButton.Width = 100;
 
  MyForm.AddNewEvent(testButton,tbeOnClick,'ShowMessage(''Hello'');');
 
  MyForm.Run;
   
   
  testButton.Caption := 'Button Caption';
  }
 
</pre>
9. Another use of Button is to add text. If we add text to our component by saying button.text, when the project is run, the title does not appear and the value you have written in the text starts to appear.
 
testButton.Text := 'Button's Text';
For example, take the value written in an TClButton component and put it in the button and show me this. Below we show you how to do this.
 
testButton.Text := testEdit.Text;
ShowMessage(testButton.Text);
 
10. Now let's design our TclButton component. Let's set the width and height first. For this, you must make the following definitions.
 
testButton.Height := 50;
testButton.Width := 150;
 
11. With the Align parameter, you can specify where you want our component to be aligned in the form. This parameter has multiple positioning properties. See the [https://www.docs.clomosy.com/index.php/Object_Properties#Align page] to learn about these features. We're going to call it the top part here. So we have to write "AlTop".
testButton.Align := alTop;
 
12. With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.
 
testButton.Margins.Left:= 50;
testButton.Margins.Right:= 10;
testButton.Margins.Top:= 50;
testButton.Margins.Bottom:= 10;
 
[[File:TclButtonMargins.png|frameless|400px]]<br><br>
 
 
13. You may want to change the appearance of the text in the tag. We will use the TextSettings parameter for this.In order to use this parameter, you have to make the following definition. Otherwise your commands will not work.<br>
testButton.StyledSettings := ssFamily;
To adjust the text size;<br>
testButton.TextSettings.Font.Size := 20;
To set the text color;<br>
testButton.TextSettings.FontColor := clAlphaColor.clHexToColor('#8a067c');
 
14. To tell you the truth, you have created a simple application that does nothing yet. Let's save and start using our project. You can save in one of two ways:<br>
Click the save icon (the button in the upper right corner) or press Ctrl + S to save the project and see what you've done on the platforms now.
 
'''Example:'''<br>
:'''Base Syntax'''
  var
    MyForm:TclForm;
    testButton : TclButton;
 
  begin
    MyForm := TclForm.Create(Self);
    testButton:= MyForm.AddNewButton(MyForm,'testButton','Click');
    testButton.TextSettings.Font.Size:=50;
    testButton.Align := alCenter;
    testButton.Height := 50;
    testButton.Width := 100;
   
    MyForm.AddNewEvent(testButton,tbeOnClick,'ShowMessage(''Hello'');');
   
    MyForm.Run;
 
  end;


:'''TRObject Syntax'''
<b>Output:</b><br>
  var
[[File:Button.png|frameless|450px]]<br>
    MyForm:TclForm;
    testButton : TclButton;
 
  {
    MyForm = TclForm.Create(Self);
    testButton= MyForm.AddNewButton(MyForm,'testButton','Click');
    testButton.TextSettings.Font.Size=50;
    testButton.Align = alCenter;
    testButton.Height = 50;
    testButton.Width = 100;
   
    MyForm.AddNewEvent(testButton,tbeOnClick,'ShowMessage(''Hello'');');
   
    MyForm.Run;
 
  }


'''Output:'''<br>
<h2> See Also </h2>
[[File:Button.png|frameless|450px]]
* [[Components]]
* [[Object Properties]]
* [[AddNewEvent]]
{{#seo:|title=TclButton Using in Clomosy - Clomosy Docs}}
{{#seo:|description=Discover TclButton in Clomosy, a versatile component for triggering actions in the UI, with customizable size, alignment, margins, and text formatting.}}

Latest revision as of 14:32, 24 December 2024

AComponent : Specifies the parent of the object to be defined.

xName : The name of the defined button should be written.

xCaption : You can add a title.

It is a component used to perform a specific action in the user interface. When a button is placed on the form, it allows the user to trigger a particular function by clicking it. For example, a "Save" button can be added to allow data to be saved.

Feature Use of Definition
TClButton Button1 : TclButton; A variable belonging to the TclButton class is created.
AddNewButton Button1 = Form1.AddNewButton(Form1,'Button1','Test Button Caption'); A new TclButton is added to the form.
Width Button1.Width = 150; Allows adjusting the width of the button.
Height Button1.Height = 50; Allows adjusting the height of the button.
Align Button1.Align = alTop; With the Align parameter, you can specify where you want our component to be aligned in the form. This parameter has multiple positioning properties. See the page to learn about these features.
Margins Button1.Margins.Left = 50; // Right, Top, Bottom With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.
TclButtonMargins.png

Caption Button1.Caption = 'Button Caption'; It represents the text displayed on the component. The Caption specifies the textual label that the component presents to the user.
Text Button1.Text = 'Button's Text'; It represents the text within the component. The text entered by the user or set by the program is managed through this property.
TextSettings Button1.StyledSettings = ssFamily;

Button1.TextSettings.FontColor = clAlphaColor.clHexToColor('#8a067c');

Button1.TextSettings.Font.Size = 20;

Button1.TextSettings.Font.Style = [fsItalic]; //[fsItalic,fsUnderline]
Text formatting is performed in the component. To see the usage, see page.


Example

 var
   MyForm:TclForm;
   testButton : TclButton;
 
 {
   MyForm = TclForm.Create(Self);
   testButton= MyForm.AddNewButton(MyForm,'testButton','Click');
   testButton.TextSettings.Font.Size=50;
   testButton.Align = alCenter;
   testButton.Height = 50;
   testButton.Width = 100;
   
   MyForm.AddNewEvent(testButton,tbeOnClick,'ShowMessage(''Hello'');');
   
   MyForm.Run;
 
 }

Output:
Button.png

See Also