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

Re: The wish to pass a value from a (child) class to a (parent) form by Ignacio

Ignacio
Mon Jun 30 14:12:59 CDT 2008

On Jun 30, 1:29=A0pm, H_stone <herstei...@gmail.com> wrote:
> 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:
>
> =A0 =A0 partial class MainForm : Form
> =A0 =A0 {
> =A0 =A0 =A0 =A0 [STAThread]
> =A0 =A0 =A0 =A0 static void Main()
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 Application.Run(new MainForm());
> =A0 =A0 =A0 =A0 }
>
> =A0 =A0 =A0 =A0 // Public accessor
> =A0 =A0 =A0 =A0 public string textToDisplayBox
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 set { this.textBox4.Text =3D value; }
> =A0 =A0 =A0 =A0 }
>
> =A0 =A0 =A0 =A0 // CommunicationManager
> =A0 =A0 =A0 =A0 CommunicationManager comm =3D new CommunicationManager();
>
> =A0 =A0 }
>
> 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 =3D new CommunicationManager( this);

Re: The wish to pass a value from a (child) class to a (parent) form class! by Jack

Jack
Mon Jun 30 17:56:09 CDT 2008

On Mon, 30 Jun 2008 10:29:37 -0700 (PDT), H_stone
<hersteinnp@gmail.com> wrote:

>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.