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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating BitBtn from code in Borland 6 1

Status
Not open for further replies.

tibord

Programmer
Apr 21, 2006
6
0
0
YU
I want to create Bit Buttons on my form.
I want to add them from code not from design.
I need this because depending on some parameters in the DB I need 8, 16 or 32 of them on a form.

Can someone tell me how to do this.

Thank you in advance.
Edit/Delete Message
 
I know that it can be done dynamically but i have never done it. I prefer to put all buttons and such on the form but make them invisible if not used. (->Visible parameter set to false)

It's also easy to resize, change picture and such.

Might not be the best solution but it's simple.

Totte
Keep making it perfect and it will end up broken.
 
I was thinking about making them invisible but i think that it would be a nicer solution to create them dynamically, but if i don't find the way to do it then I'll have to use the hiding method :(
 
The other thing is that if I create them dynamically I could put them in an array so I could manipulate them more easily, because all off them need to implement the same function, just with different parameters that I acquire for the DB.
 
Here's how I dynamically create my buttons:
Code:
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TButton *Btn;
//NumBtns is the number of buttons to create
  for (unsigned int i = 0;i<NumBtns();i++)
  {
    Btn = new TButton(this);
    AnsiString btnNum = i;
    Btn->Name = "Btn"+ btnNum;
    Btn->Caption = Btn->Name;
    Btn->OnClick = TestClick;
// TestClick is an event function; you can assign it later
// but make sure you assign an evcent function to a button
// before the user can click it
    this->InsertControl(Btn);
    Btn->Top = i * (Btn->Height);
    Btn->Width = Btn->Width *2;
    NumLines = i+1;
  };
  this->Height = (NumLines +1) * ((Btn->Height)+1);
}


The simplest solution is the best!
 
Thank you.

Currently I'm not at my computer but as soon as I get back I will try it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top