473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 1117
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Suzanne Vogel | last post by:
Hi, Given: I have a class with protected or private data members, some of them without accessor methods. It's someone else's class, so I can't change it. (eg, I can't add accessor methods to the...
2
by: Steven T. Hatton | last post by:
I find the surprising. If I derive Rectangle from Point, I can access the members of Point inherited by Rectangle _IF_ they are actually members of a Rectangle. If I have a member of type Point...
5
by: Craig Anderson | last post by:
Can anyone tell me the best way to access a hidden object in a form? I could use a hard-coded index to the elements of the form, but it's too easy to add something before the hidden object and mess...
1
by: lewi | last post by:
How do I access data members of a parent form class and from a function of a child form class. Both classes are both in the same name space and are public classes... The child form is a Modal...
3
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different...
0
by: Joergen Bech | last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running application on a web server outside of my control, but only the first time I run it: 1. After a long period of inactivity (or...
7
by: hummh | last post by:
Hello out there, I´m making my first steps with ASP.NET 2.0 and have he following problem: I´ve implemented a Web User Control that sits in the root of my ASP.NET Website. I want to use the...
12
by: Steve Blinkhorn | last post by:
Does anyone know of a way of accessing and modifying variables declared static within a function from outside that function? Please no homilies on why it's bad practice: the context is very...
7
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.