Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 9th, 2005, 3:58 PM   #1
willkoh
Newbie
 
Join Date: May 2005
Posts: 9
Rep Power: 0 willkoh is on a distinguished road
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.
willkoh is offline   Reply With Quote
Old Jul 9th, 2005, 5:05 PM   #2
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
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
Dameon is offline   Reply With Quote
Old Jul 10th, 2005, 1:38 PM   #3
willkoh
Newbie
 
Join Date: May 2005
Posts: 9
Rep Power: 0 willkoh is on a distinguished road
As I said, I did it in VB.Net so it might just be a case of me forgetting. Could someone please show?
willkoh is offline   Reply With Quote
Old Jul 10th, 2005, 2:06 PM   #4
willkoh
Newbie
 
Join Date: May 2005
Posts: 9
Rep Power: 0 willkoh is on a distinguished road
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#?
willkoh is offline   Reply With Quote
Old Jul 10th, 2005, 4:32 PM   #5
willkoh
Newbie
 
Join Date: May 2005
Posts: 9
Rep Power: 0 willkoh is on a distinguished road
...but you don't get access to the controls on the forms. Damn it.
willkoh is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:49 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC