Connecting Tech Pros Worldwide Help | Site Map

this may very well be a stupid question

dawn
Guest
 
Posts: n/a
#1: Nov 15 '05
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.


J_Max
Guest
 
Posts: n/a
#2: Nov 15 '05

re: this may very well be a stupid question


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" <dawn4715@hotmail.com> wrote in message
news:Dzjlb.96854$pV6.4587617@phobos.telenet-ops.be...[color=blue]
> 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[/color]
to[color=blue]
> write code that switches between the forms (i.e. the have to be[/color]
co-existent[color=blue]
> 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[/color]
that[color=blue]
> I can access (i.e. render active) it anywhere I like from within the code[/color]
of[color=blue]
> form1.
> And how do I actually change the active form? I've tried using[/color]
Form.Activate[color=blue]
> () but unless I'm doing something wrong (which undoubtedly is the case),[/color]
it[color=blue]
> doesn't do what I want.
>
> Sample code would be greatly appreciated,
>
> Thanks,
>
> Bart.
>
>[/color]


Peter Koen
Guest
 
Posts: n/a
#3: Nov 15 '05

re: this may very well be a stupid question


"dawn" <dawn4715@hotmail.com> wrote in
news:Dzjlb.96854$pV6.4587617@phobos.telenet-ops.be:
[color=blue]
> 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.
>
>
>[/color]


Seems like what you really need is an MDI Application.

Have a look at the following article @msdn:

http://msdn.microsoft.com/library/en...plications.asp

--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Closed Thread