Accessing objects between forms - C#, CF, WM 2003 SE

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm writing an application where I have incoming data via TCP into a Static
global routine. From that routine, I'm wanting to display the error message
on a form.

Now I have tried many variations of getting access to the object ( a message
label), but basically, as soon as it tries to assign the message label.text,
the program just stops in that code.

I'm using VS 2003 - C# - Writing for WM 2003 SE

1. I'm calling this from Public Static routine in a different namespace.
2. FSignon is the name of the form.
3. FSignon_int is a public reference to the form:
public static FSignon FSignon_int;
4. The form is displaying.
5. I'm then trying to assign the message label as follows:

public static void ipInMsg(string mytext);

FSignon.FSignon_int.MsgLabel.Text=mytext;
(debugging ends on this line)

So, how is one normally suppose to be able to assign or change values of
objects on other forms? I was thinking about window messaging .. but not
sure on the impact with CF or some Invoke statement?

Just needs some direction here.

Thanks
John
 
If the event is coming in on a separate thread (not clear from your post)
then you must use Invoke to access any UI element.

-Chris
 
I believe I am dealing with a basic mis-understanding of getting access to
objects from different classes.

1. I do have a separate thread (an event) that is taking inbound data.
2. I am parsing that data and I want to put that information into a Label
object on potentially two different forms.

So, here is the path I have:

1. Data comes in via an event in a class named 'Globals'.
2. In a "STATIC METHOD" - the event, I then decide which form should
receive the information.
3. I am then attempting to call that form's label to put the message I
received so the user can see it. (In this case, it could be either the form
named "FMain" in class "main" or in a form named "FSignon" in the class
"signon".

Now, how is this supposed to work from a static event? I've tried creating
a reference to the form's form by doing a:
===
public class FSignon: System.Windows.Forms.Form
{
public static FSignon FSignon_int;

(I saw this in another posting).
=====
But, when I tried to do this, the application stops processing:
FSignon.FSignon_int.msglabel.text="Error";

=================================
And, I also tried doing an invoke...but how are you to invoke an object
outside the class?

Thanks
John
 
Back
Top