How can I store global variables in WinForm application

G

Guest

Hi all,

I want to store some global variables in WinForm application like in Asp.Net.

For example, when user has successfully logged ini, userID and userName will be stired in global variables.

How can I do this?

Thanks!
 
M

Morten Wennevik

Hi Tony,

I'm not sure if this is the best way, but you can create a static objects and properties. Using internal (or protected internal) would make it accessible for your whole application.
 
B

Bob Powell [MVP]

Global variables can be created with static properties and members. A class
containing static properties for example would provide global access to all
classes. For Example:

class MyGlobals
{
public static int A;
public static double B;
}

class myInstance
{

protected void M()
{
MyGlobals.A=100;
MyGlobals.B=3.2425926*MyGlobals.A;
}
}

--
Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml






Tony said:
Hi all,

I want to store some global variables in WinForm application like in Asp.Net.

For example, when user has successfully logged ini, userID and userName
will be stired in global variables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top