470,833 Members | 1,315 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

Accessing Form members from outside the Form?

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
Mar 2 '06 #1
3 999
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/
Mar 2 '06 #2
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

Jochen Kalmbach [MVP] schrieb: 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...

Mar 2 '06 #3
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/
Mar 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Craig Anderson | last post: by
3 posts views Thread by Vivek Sharma | last post: by
12 posts views Thread by Steve Blinkhorn | last post: by
7 posts views Thread by Chuck Anderson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.