Neil256412

Hello,

I am fairly new at C++ so I apologise if this is a silly question:

I am trying to create a forms based application in which a whole bunch of textboxes are created when the form is loaded:

Code Block

public: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)

{

....

TextBox* TB[,] = new TextBox * [8,8] ;

for (int i=0; i<8; i++)

{

for (int j=0; j<8; j++)

{

TB[i,j] = new TextBox;

tabPage1->Controls->Add(TB[i,j]);

TB[i,j]->Location = System::Drawing::Point(10 + 45 + 45 * j, 10 + 25 + 25 * i);

TB[i,j]->Size = System::Drawing::Size(40, 20);

TB[i,j]->Text = Convert::ToString(corrMatrixPre[i][j]);

}

}

...

}

This all works fine. I then have a Button, which when pushed runs a programme. I now want to use the text in the textboxes created during runtime as inputs:

Code Block

private: System::Void toolBar1_ButtonClick(System::Object * sender, System::Windows::Forms::ToolBarButtonClickEventArgs * e)

{

...

{

penIns.corrMatrixPre[i][j]=Convert::ToDouble(Form1::TB[i,j]);

}

...

}

I get an error : TB is not a member of Form1. How do I access these objects that are created at runtime

Many Thanks,

Neil



Re: Windows Forms General Accessing information in a form TextBox when the TextBox was created at Run Time

H. Tony

you can make TextBox* TB[,] = new TextBox * [8,8] ; member variable of the class so that you can access it in other places.







Re: Windows Forms General Accessing information in a form TextBox when the TextBox was created at Run Time

Fábio

That is happening because the TextBoxes are part of the tabPage1 controls collection, not form1.

use

penIns.corrMatrixPreIdea[j]=Convert::ToDouble(tabPage1::TB[i,j]);

instead.