Difference between revisions of "TGroupBox"
From Free Pascal wiki
Jump to navigationJump to searchLine 1: | Line 1: | ||
+ | |||
+ | |||
{{TGroupBox}} | {{TGroupBox}} | ||
− | A '''TGroupBox''' [[image:tgroupbox.png]] is a container that allows a number of objects to be grouped physically and conceptually on a form. | + | A '''TGroupBox''' [[image:tgroupbox.png]] is a container that allows a number of objects to be grouped physically and conceptually on a [[TForm|form]]. |
==Usage== | ==Usage== | ||
− | To use a [[doc:lcl/stdctrls/tgroupbox.html|TGroupBox]] on a | + | To use a [[doc:lcl/stdctrls/tgroupbox.html|TGroupBox]] on a form, you can simply select it on the [[Standard tab]] of the [[Component Palette]] and place it by clicking on the form. |
==Small example== | ==Small example== | ||
Line 10: | Line 12: | ||
* in GroupBox1 insert a [[TButton]] ''Button1'' and in GroupBox2 TButton ''Button2'' | * in GroupBox1 insert a [[TButton]] ''Button1'' and in GroupBox2 TButton ''Button2'' | ||
* put on your form (outside of the groupboxes) two [[TRadioButton]] | * put on your form (outside of the groupboxes) two [[TRadioButton]] | ||
− | * change in the object Inspector the caption of RadioButton1 to ''User'' and of RadioButton2 to ''Administrator'' | + | * change in the [[IDE_Window:_Object_Inspector|object Inspector]] the caption of RadioButton1 to ''User'' and of RadioButton2 to ''Administrator'' |
− | * change the property ''Checked'' of RadioButton2 to ''True'' | + | * change the [[Property|property]] ''Checked'' of RadioButton2 to ''[[True]]'' |
− | * create the ''OnChange'' event handler of RadioButton1 by double clicking ''RadioButton1'' | + | * create the ''OnChange'' [[Event handler|event handler]] of RadioButton1 by double clicking ''RadioButton1'' |
* use this handler also for RadioButton2 | * use this handler also for RadioButton2 | ||
** choose in the object Inspector ''RadioButton2' | ** choose in the object Inspector ''RadioButton2' | ||
Line 19: | Line 21: | ||
* make ''GroupBox2'' for user invisible by choosing in the RadioButton | * make ''GroupBox2'' for user invisible by choosing in the RadioButton | ||
** write following line in the event handler of the RadioButtons in the source editor: | ** write following line in the event handler of the RadioButtons in the source editor: | ||
− | < | + | <syntaxhighlight lang="Pascal"> |
procedure TForm1.RadioButton1Change(Sender: TObject); | procedure TForm1.RadioButton1Change(Sender: TObject); | ||
begin | begin | ||
GroupBox2.Visible:=Radiobutton2.Checked; | GroupBox2.Visible:=Radiobutton2.Checked; | ||
end; | end; | ||
− | </ | + | </syntaxhighlight> |
* add still the event handler of the buttons and add some code like: | * add still the event handler of the buttons and add some code like: | ||
− | < | + | <syntaxhighlight lang="Pascal"> |
procedure TForm1.Button1Click(Sender: TObject); | procedure TForm1.Button1Click(Sender: TObject); | ||
begin | begin | ||
− | ShowMessage(' | + | ShowMessage('User and administrator can click this button'); |
end; | end; | ||
procedure TForm1.Button2Click(Sender: TObject); | procedure TForm1.Button2Click(Sender: TObject); | ||
begin | begin | ||
− | ShowMessage('Only | + | ShowMessage('Only administrator can click this button'); |
end; | end; | ||
− | </ | + | </syntaxhighlight> |
+ | * it shows in the [[Dialog_Examples#ShowMessage|ShowMessage dialog]] who can press the button | ||
* start your program, it could look like: | * start your program, it could look like: | ||
Latest revision as of 09:16, 15 September 2019
│
Deutsch (de) │
English (en) │
suomi (fi) │
français (fr) │
日本語 (ja) │
русский (ru) │
A TGroupBox is a container that allows a number of objects to be grouped physically and conceptually on a form.
Usage
To use a TGroupBox on a form, you can simply select it on the Standard tab of the Component Palette and place it by clicking on the form.
Small example
- create a new application and place two TGroupBoxes on your form
- in GroupBox1 insert a TButton Button1 and in GroupBox2 TButton Button2
- put on your form (outside of the groupboxes) two TRadioButton
- change in the object Inspector the caption of RadioButton1 to User and of RadioButton2 to Administrator
- change the property Checked of RadioButton2 to True
- create the OnChange event handler of RadioButton1 by double clicking RadioButton1
- use this handler also for RadioButton2
- choose in the object Inspector RadioButton2'
- now select the tab Events in the object Inspector
- go to the event OnChange and select in the adjacent combobox RadioButton1Change
- make GroupBox2 for user invisible by choosing in the RadioButton
- write following line in the event handler of the RadioButtons in the source editor:
procedure TForm1.RadioButton1Change(Sender: TObject);
begin
GroupBox2.Visible:=Radiobutton2.Checked;
end;
- add still the event handler of the buttons and add some code like:
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('User and administrator can click this button');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage('Only administrator can click this button');
end;
- it shows in the ShowMessage dialog who can press the button
- start your program, it could look like:
See also