Difference between revisions of "TGroupBox"
From Lazarus wiki
Jump to navigationJump to searchm (Preparation for translation) |
(Usage added) |
||
Line 13: | Line 13: | ||
==Usage== | ==Usage== | ||
− | + | To use a [[doc:lcl/stdctrls/tgroupbox.html|TGroupBox]] on a [[TForm|form]], you can simply select it on the ''Standard'' component pallet and place it by clicking on the form.<br> | |
+ | ====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: | ||
+ | <source> | ||
+ | procedure TForm1.RadioButton1Change(Sender: TObject); | ||
+ | begin | ||
+ | GroupBox2.Visible:=Radiobutton2.Checked; | ||
+ | end; | ||
+ | </source> | ||
+ | * add still the event handler of the buttons and add some code like: | ||
+ | <source> | ||
+ | procedure TForm1.Button1Click(Sender: TObject); | ||
+ | begin | ||
+ | ShowMessage('Users and administrators can click this button'); | ||
+ | end; | ||
+ | |||
+ | procedure TForm1.Button2Click(Sender: TObject); | ||
+ | begin | ||
+ | ShowMessage('Only administrators can click this button'); | ||
+ | end; | ||
+ | </source> | ||
+ | * start your program, it could look like: | ||
+ | |||
+ | [[image:ExampleTGroupBox1.png]] -> [[image:ExampleTGroupBox2.png]] | ||
+ | |||
+ | ==See also== | ||
+ | [[TPanel]]<br> | ||
+ | [[TPairSplitter]]<br> | ||
+ | [[TNotebook]]<br> | ||
+ | [[TPageControl]]<br> | ||
+ | [[TTabControl]]<br> | ||
Revision as of 22:41, 26 June 2014
│
Deutsch (de) │
English (en) │
suomi (fi) │
français (fr) │
日本語 (ja) │
русский (ru) │
>> LCL Components >> TGroupBox
This page explains how to use the TGroupBox component. When I mention to click on something, unless I explicitly say to right-click, you always left-click on the item in question.
Description
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 component pallet 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('Users and administrators can click this button');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage('Only administrators can click this button');
end;
- start your program, it could look like:
See also
TPanel
TPairSplitter
TNotebook
TPageControl
TTabControl
Return To: LCL Components | — Previous: TScrollBar | Next: TRadioGroup |
--Michl 08:53, 25 June 2014 (CEST)