Accessing Form members from outside the Form?

  • Thread starter Thread starter R.Kaiser
  • Start date Start date
R

R.Kaiser

In a VS2005 Windows Forms Application I have an ordinary class like

class C{
int x;
public:
C(int x_):x(x_) { }
void display()
{
// Here I want to access a TextBox Form member
// Form???->textBox1->Text=(x).ToString();
}
};

In one of its member function I want to do some output to a TextBox on a
Form, like in the display function above.

Is there any way to do this?

Thanks
Richard
 
Hi R.!
In a VS2005 Windows Forms Application I have an ordinary class like

class C{
int x;
public:
C(int x_):x(x_) { }
void display()
{
// Here I want to access a TextBox Form member
// Form???->textBox1->Text=(x).ToString();
}
};

In one of its member function I want to do some output to a TextBox on a
Form, like in the display function above.

You should provide a property in your Form-class which returns the stuff
from your private member:

class FormXxx : public Form
{
public:
property String^ MyData
{
return textBox1->Text;
}
property void MyData(String ^text)
{
textBox1->Text = text;
}
};

Then you can access it from outside via:

// Here I want to access a TextBox Form member
Form???->MyData = (x).ToString();

You also can cosider to pass paramters in the constructor of your Form...


--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Thanks.

But how can I access the Form in a Windows Forms Application? There
seems to be no global object like the one you are using by "Form???"
Then you can access it from outside via:

// Here I want to access a TextBox Form member
Form???->MyData = (x).ToString();

Richard
 
Hi R!
But how can I access the Form in a Windows Forms Application? There
seems to be no global object like the one you are using by "Form???"

Hmmmm....

Normaly you have some class which is dereived from Form.
To show this form, you need to instanciate your Form:

class MyForm : public Form
{
// some other stuff
};

Usage:
MyForm ^myForm = gcnew MyForm();
myForm->MyData = "My Text";
myForm->ShowDialog();



Or what do you mean?

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Back
Top