Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create few checkboxes in runtime 1

Status
Not open for further replies.

zvikorn

Programmer
Aug 6, 2003
17
0
0
US
Hello,
I would like to ask the user in the GUI, for a real number, and according this number, to create lines of checkboxes. Which means, if the user will enter as an input number 8, the GUI will show on the form, 8 lines ,each line contains one checkbox. It does not matter for me, which component to use in order to have those checkboxes.
Can someone pls assist?
Thanks a lot
Tzvi
 
Use the new operator in a loop to initialize each instance of the checkboxes you need. After you instantiate a new checkbox, set it's parent property to the form where you want the checkbox. Then set it's Left, Top, Width, and Height properties to what you want. Use a multiplier of the loop variable in the Top property setting to make a series of vertical rows of checkboxes.

Good luck,
Chris
 
I agree with Supernat03,

The source code is something like this:
On a event write this, I did it in a Form OnCreate

int Heigth = 30; //Height for the check box
int Width = 200; //Width for the check box


void __fastcall TForm1::Create (TObject *Sender)
{
int Col, Row;
TCheckBox *CheckBoxCreatedInRunTime;
Col = 100;
Row = 100 + Height;
for (int i=1; i<=10; i++)
{
CheckBoxCreatedInRunTime = new TCheckBox(this);
CheckBoxCreatedInRunTime->Left = Col;
CheckBoxCreatedInRunTime->Top = Row;
CheckBoxCreatedInRunTime->Caption = &quot;Check &quot; + String (i);
CheckBoxCreatedInRunTime->Name = &quot;Check &quot; + String (i);
CheckBoxCreatedInRunTime->Parent->Form1;
CheckBoxCreatedInRunTime->OnClick= AnyEvent;

Row += Height;
if (i%5 == 0)
{
Col += Width;
Row = 100 + Height;
}
}
}






}







--- LastCyborg ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top