473,387 Members | 1,493 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,387 software developers and data experts.

The wish to pass a value from a (child) class to a (parent) formclass!

I have a MainForm class and a second class which initializes an
instance of a second class which I call CommunicationManager.

This is just a simplified representation of the MainForm class:

partial class MainForm : Form
{
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}

// Public accessor
public string textToDisplayBox
{
set { this.textBox4.Text = value; }
}

// CommunicationManager
CommunicationManager comm = new CommunicationManager();

}

The CommunicationManager class has a simple function, i.e. to collect
in a string the output from the comport...

My troubles stem from the fact that I am unable to reference back to
the form which second class is initiated.

Do you have any suggestions on how to achieve this?

Best regards,
H
Jun 30 '08 #1
2 1211
On Jun 30, 1:29*pm, H_stone <herstei...@gmail.comwrote:
I have a MainForm class and a second class which initializes an
instance of a second class which I call CommunicationManager.

This is just a simplified representation of the MainForm class:

* * partial class MainForm : Form
* * {
* * * * [STAThread]
* * * * static void Main()
* * * * {
* * * * * * Application.Run(new MainForm());
* * * * }

* * * * // Public accessor
* * * * public string textToDisplayBox
* * * * {
* * * * * * set { this.textBox4.Text = value; }
* * * * }

* * * * // CommunicationManager
* * * * CommunicationManager comm = new CommunicationManager();

* * }

The CommunicationManager class has a simple function, i.e. to collect
in a string the output from the comport...

My troubles stem from the fact that I am unable to reference back to
the form which second class is initiated.

Do you have any suggestions on how to achieve this?

Best regards,
H
Hi,

It's not very clear from your post where is your problem.
You can pass to the contructor of CommunicationManager a reference to
your form
CommunicationManager comm = new CommunicationManager( this);
Jun 30 '08 #2
On Mon, 30 Jun 2008 10:29:37 -0700 (PDT), H_stone
<he********@gmail.comwrote:
>I have a MainForm class and a second class which initializes an
instance of a second class which I call CommunicationManager.

This is just a simplified representation of the MainForm class:

partial class MainForm : Form
{
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}

// Public accessor
public string textToDisplayBox
{
set { this.textBox4.Text = value; }
}

// CommunicationManager
CommunicationManager comm = new CommunicationManager();

}

The CommunicationManager class has a simple function, i.e. to collect
in a string the output from the comport...

My troubles stem from the fact that I am unable to reference back to
the form which second class is initiated.

Do you have any suggestions on how to achieve this?

Best regards,
H
The best way to do this is to create a public Event in
CommunicationManager and subscribe to that event in the form.

The event should have two arguments, the first of type 'object' that
is a reference to the instance of CommunicationManager that raises the
event, and a second argument that is an instance of a class derived
from System.EventArgs that includes the data that needs to be passed
to the form.
Jun 30 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Filiz Duman | last post by:
Hi, I am opening a pop up window (child) from a parent window. The Child window does show a table with multiple columns and rows, each showing a value, e.g. 9 or 10 or etc. I have the values as...
4
by: Davey | last post by:
I have a website which has a popup window (this only opens when the user chooses to open it). In the popup window I have a <select> control which lists a selection of "classes". Each class has a...
1
by: Mel | last post by:
I am in my class and I want to invoke a method on my form. I made my form method public. But I don't see it through intellisensing. Any ideas?
8
by: darrel | last post by:
I'm still trying to fully understand how best to pass variables between pages/usercontrols/each other. On a current site I've done, I've had one userControl do the logic and set the variable,...
10
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++)...
6
by: kath | last post by:
hi everyone......... I have a task, I have fragmented the task into subtask. I have planned to create a class to each subclass and one parent class to handle the sub tasks. Each subclass are...
5
by: Rob | last post by:
I have a control (Button) on a Parent form which opens a Windows form... all I want to do is pass a value from the child form back to the parent... it should be so simple... i.e....
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.