By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,453 Members | 1,562 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,453 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.