Greetings.
This is a subject that is very dear to my heart, something that I hope I'll
never forget, as long as I program C# -- I spent about a week trying to
figure this out.
It is really simple. Like this:
Here is the form that you want to access:
using System.Forms;
namespace My_Program
{
public class Form1 : System.Windows.Forms.Form
{
public static Form1 self = null; // this is the variable that we
will be accessing later - very import line. Static means that anywhere can
access and change it. Also the variable that you want to access MUST be
public.
public string text; // remember the public parameter
public Form1()
{
self = this; //this is where we assign what self is.
text = "Hello World!";
}
... rest of code
Here is an example of how to access Form1 from Form2;
public void AccessForm1 ()
{
MessageBox.Show(Form1.self.text);
}
Best,
J_Max
"dawn" <da******@hotmail.com> wrote in message
news:Dz*********************@phobos.telenet-ops.be...
Hi,
I'm writing a Windows Form app, using c# (and believe me when I say I'm a
newbie). The program needs two forms to functionate and I have to be able
to write code that switches between the forms (i.e. the have to be
co-existent and I need to change the Active Form). I launch the second form from the
menu bar in the frst form.
How can I make this second form "known" throughout the entire code, so
that I can access (i.e. render active) it anywhere I like from within the code
of form1.
And how do I actually change the active form? I've tried using
Form.Activate () but unless I'm doing something wrong (which undoubtedly is the case),
it doesn't do what I want.
Sample code would be greatly appreciated,
Thanks,
Bart.