From Clomosy Docs

No edit summary
No edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
CheckBox represents a TclCheckBox style checkbox that can be open (selected) or closed (cleared). The CheckBox component gives you a choice. Select the box to turn the option on or clear the box to turn the option off.
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
function AddNewCheckBox(AComponent: TCLComponent; xName, xCaption: string): TclCheckBox;
</div>


AddNewCheckBox(TComponent, xName, xCaption): TclCheckBox
<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 chechbox should be written.<br>


<span style="color:blue"> xName</span> : The name of the defined chechbox 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.
CheckBox represents a TclCheckBox style checkbox that can be open (selected) or closed (cleared). The CheckBox component gives you a choice. Select the box to turn the option on or clear the box to turn the option off.<br>


Let's create a checkbox.<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
|-
|TclCheckBox || CheckBox1 : TclCheckBox; || A variable belonging to the TclCheckBox class is created.
|-
|AddNewCheckBox || CheckBox1 = Form1.AddNewCheckBox(Form1,'CheckBox1','Test CheckBox Caption'); || A new TclCheckBox is added to the form.
|-
|Width || CheckBox1.Width = 150; ||Allows adjusting the width of the checkbox.
|-
|Height || CheckBox1.Height = 50; ||Allows adjusting the height of the checkbox.
|-
|Align  || CheckBox1.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 || CheckBox1.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:TclCheckBoxMargins.png|frameless|200px]]<br><br>
|-
|TextSettings || CheckBox1.StyledSettings = ssFamily;<br><br>CheckBox1.TextSettings.FontColor = clAlphaColor.clHexToColor('#8a067c');<br><br>CheckBox1.TextSettings.Font.Size = 20;<br><br>CheckBox1.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].
|-
|Text ||CheckBox1.Text = 'CheckBox''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.
|-
|isChecked ||CheckBox1.isChecked = True; || Assign the value True or False to the Checked property to change the checkBox's visual state. As soon as it is correct, it will come selected.
|}
</div>


1. Create a new project.<br>


2. You need to define TclCheckBox 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 TclCheckBox.<br>
'''var'''
testCheckBox : TclCheckBox;


3. Add the TclCheckBox 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.AddNewCheckBox, we actually add to the form we have defined. Here, you need to add your form definition as whatever you wrote it.<br>
<h2>Example 1</h2><br>
 
<pre>
  testCheckBox := ''MyForm''.AddNewCheckBox(MyForm,'testCheckBox','Test CheckBox Caption');
  var
 
  MyForm:TclForm;
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.
  testButton : TclButton;
<span style="color:blue">testLayout</span> := MyForm.AddNewLayout(MyForm,'testLayout');
  testLabel : TclLabel;
testCheckBox := MyForm.AddNewCheckBox(<span style="color:blue">testLayout</span>,'testCheckBox','Test CheckBox Caption');
  testCheckBox,testCheckBox2 : TClCheckBox;
 
5. While defining the component, you can define it manually by typing. Another method is to write its shortcut. If you type "AddNewCheckBox" while the shortcut is in the code block, a pop-up menu will appear.<br>
   
   
[[File:TclCheckBoxShortcut.png|frameless|400px]]<br><br>
void ButtonClicked;
 
{
6. We gave the variable name while defining the TclCheckBox 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.
  testCheckBox.isChecked = not testCheckBox.isChecked;
 
  testCheckBox2.isChecked = not testCheckBox2.isChecked;
7. You give a title to your Checkbox 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.
}
   
   
  testCheckBox := ''MyForm''.AddNewCheckBox(MyForm,'testCheckBox',<nowiki>''</nowiki>);
  {
  MyForm = TclForm.Create(Self);
  testButton= MyForm.AddNewButton(MyForm,'testButton','Click');
  testButton.TextSettings.Font.Size=50;
  testButton.Align = alCenter;
  testButton.Height = 50;
  testButton.Width = 100;
 
  testLabel = MyForm.AddNewLabel(MyForm,'testLabel','Your hobbies?');
  testLabel.StyledSettings = ssFamily;
  testLabel.TextSettings.Font.Size=25;
  testLabel.TextSettings.FontColor = clAlphaColor.clHexToColor('#4a08ff');
  testLabel.Align = alMostTop;
  testLabel.Height = 30;
 
  testCheckBox = MyForm.AddNewCheckBox(MyForm,'testCheckBox','Reading book');
  testCheckBox.StyledSettings = ssFamily;
  testCheckBox.TextSettings.Font.Size=15;
  testCheckBox.TextSettings.FontColor = clAlphaColor.clHexToColor('#272643');
  testCheckBox.Align = alTop;
  testCheckBox.Height = 30;
 
  testCheckBox2 = MyForm.AddNewCheckBox(MyForm,'testCheckBox2','Watching movie');
  testCheckBox2.StyledSettings = ssFamily;
  testCheckBox2.TextSettings.Font.Size=15;
  testCheckBox2.TextSettings.FontColor = clAlphaColor.clHexToColor('#272643');
  testCheckBox2.Align = alTop;
  testCheckBox2.Height = 30;
 
  MyForm.AddNewEvent(testButton,tbeOnClick,'ButtonClicked');
 
  MyForm.Run;
}
</pre>


8. Another use of Checkbox is to add text. If we add text to our component by saying testCheckBox.text, when the project is run, the title does not appear and the value you have written in the text starts to appear.


testCheckBox.Text := 'CheckBox's Text';
<b>Output:</b><br>
[[File:CheckBox.png|frameless|450px]]<br>


For example, take the value written in an TclEdit component and put it in the checkbox and show me this. Below we show you how to do this.
<h2>Example 2</h2><br>
Here is an example similar to the first one. It only involves the clicking of a checkbox component.<br>


testCheckBox.Text := testEdit.Text;
<pre>
  ShowMessage(testCheckBox.Text);
  var
 
  Form1:TclForm;
9. Now let's design our TclCheckBox component. Let's set the width and height first. For this, you must make the following definitions.
  Label1 : TclLabel;
 
  CheckBox1,CheckBox2 : TClCheckBox;
testCheckBox.Height := 50;
   
testCheckBox.Width := 150;
  void CheckBoxClicked;
 
  var
10. 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".
  senderCheckBox:TClCheckBox;
testCheckBox.Align := alTop;
  {
 
  senderCheckBox = TClCheckBox(Form1.Clsender);
11. With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.
  if senderCheckBox.clTagInt == 1 //CheckBox1 kontrol
 
    CheckBox2.isChecked = senderCheckBox.isChecked
  testCheckBox.Margins.Left:= 50;
   else if senderCheckBox.clTagInt == 2 //CheckBox1 kontrol
  testCheckBox.Margins.Right:= 10;  
    CheckBox1.isChecked = senderCheckBox.isChecked
  testCheckBox.Margins.Top:= 50;
  }
testCheckBox.Margins.Bottom:= 10;
   
 
  {
[[File:TclCheckBoxMargins.png|frameless|400px]]<br><br>
  Form1 = TclForm.Create(Self);
 
 
As seen in the example above, you do not need to set margins for every field. For example, it didn't make any sense to give us the "Bottom" and "Right" aspects here. Because we have positioned our component on the top and left side here, and we have given spaces to prevent it from sticking to the edges.
  Label1 = Form1.AddNewLabel(Form1,'Label1','Your hobbies?');
 
  Label1.StyledSettings = ssFamily;
12. 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>
  Label1.TextSettings.Font.Size=25;
  testCheckBox.StyledSettings := ssFamily;
  Label1.TextSettings.FontColor = clAlphaColor.clHexToColor('#4a08ff');
To adjust the text size;<br>
  Label1.Align = alMostTop;
testCheckBox.TextSettings.Font.Size := 20;
  Label1.Height = 30;
To set the text color;<br>
 
testCheckBox.TextSettings.FontColor := clAlphaColor.clHexToColor('#8a067c');
  CheckBox1 = Form1.AddNewCheckBox(Form1,'CheckBox1','Reading book');
 
  CheckBox1.StyledSettings = ssFamily;
13. Assign the value True or False to the Checked property to change the checkBox's visual state. As soon as it is correct, it will come selected.<br>
  CheckBox1.TextSettings.Font.Size=15;
'''Use Of:'''<br>
  CheckBox1.TextSettings.FontColor = clAlphaColor.clHexToColor('#272643');
testCheckBox.isChecked := True;
  CheckBox1.Align = alTop;
 
  CheckBox1.Height = 30;
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>
  CheckBox1.clTagInt = 1;
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.
 
 
  CheckBox2 = Form1.AddNewCheckBox(Form1,'CheckBox2','Watching movie');
 
  CheckBox2.StyledSettings = ssFamily;
'''Example:'''<br>
  CheckBox2.TextSettings.Font.Size=15;
'''var'''
  CheckBox2.TextSettings.FontColor = clAlphaColor.clHexToColor('#272643');
MyForm:TclForm;
  CheckBox2.Align = alTop;
testButton : TclButton;
  CheckBox2.Height = 30;
testLabel : TclLabel;
  CheckBox2.clTagInt = 2;
testCheckBox,testCheckBox2 : TClCheckBox;<br>
  Form1.AddNewEvent(CheckBox2,tbeOnClick,'CheckBoxClicked');
'''procedure''' ButtonClicked;
  Form1.AddNewEvent(CheckBox1,tbeOnClick,'CheckBoxClicked');
'''begin'''
 
   testCheckBox.isChecked := not testCheckBox.isChecked;
  Form1.Run;
  testCheckBox2.isChecked := not testCheckBox2.isChecked;
  }
  '''end;'''<br>
</pre>
  '''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;<br>
testLabel := MyForm.AddNewLabel(MyForm,'testLabel','Your hobbies?');
testLabel.StyledSettings := ssFamily;
testLabel.TextSettings.Font.Size:=25;
testLabel.TextSettings.FontColor := clAlphaColor.clHexToColor('#4a08ff');
testLabel.Align := alMostTop;
testLabel.Height := 30;<br>
testCheckBox := MyForm.AddNewCheckBox(MyForm,'testCheckBox','Reading book');
testCheckBox.StyledSettings := ssFamily;
testCheckBox.TextSettings.Font.Size:=15;
testCheckBox.TextSettings.FontColor := clAlphaColor.clHexToColor('#272643');
testCheckBox.Align := alTop;
testCheckBox.Height := 30;<br>
testCheckBox2 := MyForm.AddNewCheckBox(MyForm,'testCheckBox2','Watching movie');
testCheckBox2.StyledSettings := ssFamily;
testCheckBox2.TextSettings.Font.Size:=15;
testCheckBox2.TextSettings.FontColor := clAlphaColor.clHexToColor('#272643');
testCheckBox2.Align := alTop;
testCheckBox2.Height := 30;<br>
MyForm.AddNewEvent(testButton,tbeOnClick,'ButtonClicked');<br>
MyForm.Run;
  '''end;'''
'''Output:'''<br>
[[File:CheckBox.png|frameless|450px]]


= See Also =
<h2> See Also </h2>
* [[Components]]
* [[Object Properties]]
* [[Object Properties]]
* [[AddNewEvent]]
* [[AddNewEvent]]
{{#seo:|title=TclCheckBox Using in Clomosy - Clomosy Docs}}
{{#seo:|description=Discover TclCheckBox in Clomosy, a customizable checkbox component allowing selection or deselection, ideal for user choices in forms and interfaces.}}

Latest revision as of 14:48, 24 December 2024

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

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

xCaption : You can add a title.

CheckBox represents a TclCheckBox style checkbox that can be open (selected) or closed (cleared). The CheckBox component gives you a choice. Select the box to turn the option on or clear the box to turn the option off.

Feature Use of Definition
TclCheckBox CheckBox1 : TclCheckBox; A variable belonging to the TclCheckBox class is created.
AddNewCheckBox CheckBox1 = Form1.AddNewCheckBox(Form1,'CheckBox1','Test CheckBox Caption'); A new TclCheckBox is added to the form.
Width CheckBox1.Width = 150; Allows adjusting the width of the checkbox.
Height CheckBox1.Height = 50; Allows adjusting the height of the checkbox.
Align CheckBox1.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 CheckBox1.Margins.Left = 50; // Right, Top, Bottom With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.
TclCheckBoxMargins.png

TextSettings CheckBox1.StyledSettings = ssFamily;

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

CheckBox1.TextSettings.Font.Size = 20;

CheckBox1.TextSettings.Font.Style = [fsItalic]; //[fsItalic,fsUnderline]
Text formatting is performed in the component. To see the usage, see page.
Text CheckBox1.Text = 'CheckBoxs Text'; It represents the text within the component. The text entered by the user or set by the program is managed through this property.
isChecked CheckBox1.isChecked = True; Assign the value True or False to the Checked property to change the checkBox's visual state. As soon as it is correct, it will come selected.


Example 1


 var
   MyForm:TclForm;
   testButton : TclButton;
   testLabel : TclLabel;
   testCheckBox,testCheckBox2 : TClCheckBox;
 
 void ButtonClicked;
 {
   testCheckBox.isChecked = not testCheckBox.isChecked;
   testCheckBox2.isChecked = not testCheckBox2.isChecked;
 }
 
 {
   MyForm = TclForm.Create(Self);
   testButton= MyForm.AddNewButton(MyForm,'testButton','Click');
   testButton.TextSettings.Font.Size=50;
   testButton.Align = alCenter;
   testButton.Height = 50;
   testButton.Width = 100;
   
   testLabel = MyForm.AddNewLabel(MyForm,'testLabel','Your hobbies?');
   testLabel.StyledSettings = ssFamily;
   testLabel.TextSettings.Font.Size=25;
   testLabel.TextSettings.FontColor = clAlphaColor.clHexToColor('#4a08ff');
   testLabel.Align = alMostTop;
   testLabel.Height = 30;
   
   testCheckBox = MyForm.AddNewCheckBox(MyForm,'testCheckBox','Reading book');
   testCheckBox.StyledSettings = ssFamily;
   testCheckBox.TextSettings.Font.Size=15;
   testCheckBox.TextSettings.FontColor = clAlphaColor.clHexToColor('#272643');
   testCheckBox.Align = alTop;
   testCheckBox.Height = 30;
   
   testCheckBox2 = MyForm.AddNewCheckBox(MyForm,'testCheckBox2','Watching movie');
   testCheckBox2.StyledSettings = ssFamily;
   testCheckBox2.TextSettings.Font.Size=15;
   testCheckBox2.TextSettings.FontColor = clAlphaColor.clHexToColor('#272643');
   testCheckBox2.Align = alTop;
   testCheckBox2.Height = 30;
   
   MyForm.AddNewEvent(testButton,tbeOnClick,'ButtonClicked');
   
   MyForm.Run;
 }


Output:
CheckBox.png

Example 2


Here is an example similar to the first one. It only involves the clicking of a checkbox component.

 var
   Form1:TclForm;
   Label1 : TclLabel;
   CheckBox1,CheckBox2 : TClCheckBox;
 
 void CheckBoxClicked;
 var
   senderCheckBox:TClCheckBox;
 {
   senderCheckBox = TClCheckBox(Form1.Clsender);
   if senderCheckBox.clTagInt == 1 //CheckBox1 kontrol
     CheckBox2.isChecked =  senderCheckBox.isChecked 
   else if senderCheckBox.clTagInt == 2 //CheckBox1 kontrol
     CheckBox1.isChecked = senderCheckBox.isChecked
 }
 
 {
   Form1 = TclForm.Create(Self);
   
   Label1 = Form1.AddNewLabel(Form1,'Label1','Your hobbies?');
   Label1.StyledSettings = ssFamily;
   Label1.TextSettings.Font.Size=25;
   Label1.TextSettings.FontColor = clAlphaColor.clHexToColor('#4a08ff');
   Label1.Align = alMostTop;
   Label1.Height = 30;
   
   CheckBox1 = Form1.AddNewCheckBox(Form1,'CheckBox1','Reading book');
   CheckBox1.StyledSettings = ssFamily;
   CheckBox1.TextSettings.Font.Size=15;
   CheckBox1.TextSettings.FontColor = clAlphaColor.clHexToColor('#272643');
   CheckBox1.Align = alTop;
   CheckBox1.Height = 30;
   CheckBox1.clTagInt = 1;
   
   CheckBox2 = Form1.AddNewCheckBox(Form1,'CheckBox2','Watching movie');
   CheckBox2.StyledSettings = ssFamily;
   CheckBox2.TextSettings.Font.Size=15;
   CheckBox2.TextSettings.FontColor = clAlphaColor.clHexToColor('#272643');
   CheckBox2.Align = alTop;
   CheckBox2.Height = 30;
   CheckBox2.clTagInt = 2;
   Form1.AddNewEvent(CheckBox2,tbeOnClick,'CheckBoxClicked');
   Form1.AddNewEvent(CheckBox1,tbeOnClick,'CheckBoxClicked');
   
   Form1.Run;
 }

See Also