views:

37

answers:

2

I'm trying to create a visual c++ application which has a button that when clicked creates a text box, and when clicked again creates a text box underneath the last one created. Then a button which deletes the previously created text box.

Where do I start? Does anyone have any samples of this?

Thank you!

A: 

Create all the textboxes you need, within reason of course. Place them where you want them.

Then call their Hide() and Show() functions to make them appear and disappear.

Call SetBounds(...) if you have to move the control.

JustBoo
A: 

Create a data structure to hold your textboxes, then add them to your form on click, or delete them:

Generic::List<TextBox^>^ textBoxes;

void MainForm() //Constructor
{
    textBoxes = gcnew Generic::List<TextBox^>();
}

void btnAddClick(System::Object^  sender, System::EventArgs^  e)
{
    TextBox ^ newTextbox = gcnew TextBox();
    //Set up some properties. Location and etc.
    //...
    //...

    textBoxes.Add(newTextbox);
    MainForm.Controls.Add(newTextbox);        
}

The code is untested, but you get the idea. Deleting would be similar, just call the Remove method for the MainForm and the List.

Nathan