![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2005
Posts: 9
Rep Power: 0
![]() |
Getting form- ref. across modules?
How can I get a reference to an instance of each of my appplication's forms at startup, that will be valid everywhere?
It may be that the right style of programming is to run a new instance of it that is disposed when it closes. But if you want to do it the way I described, it must be possible somehow, right? I did it in VB.Net. |
|
|
|
|
|
#2 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Are you referring to the way that forms worked in VB 6 and below? There isn't a difference between how C# and VB .Net handle forms. Look up the singleton pattern if you want it to be somewhat similar to VB 6 forms.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#3 |
|
Newbie
Join Date: May 2005
Posts: 9
Rep Power: 0
![]() |
As I said, I did it in VB.Net so it might just be a case of me forgetting. Could someone please show?
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: May 2005
Posts: 9
Rep Power: 0
![]() |
OK, I'm now beeing more specific, and I've solved it a way that some people might like more than singelton (i'm not saying I invtented something, just thought maybe someone wonders allong the same lines):
using System.Windows.Forms;
using System;
public class app {
public static Form1 finF1 = new Form1();
public static Form2 finF2 = new Form2();
[STAThread]
static void Main()
{
finF2.Show();
Application.Run(finF1);
}
}The thing is finXX has to be static. I don't know why... Could someone explain? I've also removed the namespace around the forms and app clases for shorter access path. The forms are accesed by app.XX. Forms must be started by Show (at any time you like) except the one to appear when the app starts that starts with Application.Run(xx) In VB though, you could get rid of the "app." part. I guess that's not possible in c#? |
|
|
|
|
|
#5 |
|
Newbie
Join Date: May 2005
Posts: 9
Rep Power: 0
![]() |
...but you don't get access to the controls on the forms. Damn it.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|