Re: Global application variables in WinForms app
pdavis68_at_hotmail.com
Date: 05/31/04
- Next message: Stoitcho Goutsev \(100\) [C# MVP]: "Re: how to get .net designer frame articles?"
- Previous message: pdavis68_at_hotmail.com: "Inconsistent access levels???"
- In reply to: David McCormack: "Global application variables in WinForms app"
- Next in thread: Jeff Mastry: "Re: Global application variables in WinForms app"
- Reply: Jeff Mastry: "Re: Global application variables in WinForms app"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 31 May 2004 14:57:54 GMT
Use a class with static members. Occasionally, I will create a class called
Global where all the members are static so that I can access the members
from any class.
class Globals
{
public static int myGlobalField;
}
then from anywhere in the app, simply do:
Globals.myGlobalField = x;
or
x = Globals.myGlobalField;
simple.
Pete
"David McCormack" <nospam@zamang.co.uk> wrote in message
news:1086014677.10734.0@damia.uk.clara.net...
> I have a small project that I'm writing to help me learn C# and the .Net
> Framework. This project is a WinForms program with multiple forms that
> accesses MSDE. I've got most of it done but I've hit a slight brick wall.
>
> Does anyone have any recommended strategies for dealing with application
> wide variables? i.e. the user name of the current user that's logged in
> to the application rather than the PC.
>
> The best idea I've come up with so far is to store the items in the
> Windows registry, so they can be read as and when required, but its not
> ideal. Every other idea I've come-up with requires objects to be passed
> to single form when its opened, which I would rather not do as it'll
> mean override routines in every single form.
>
> Looking on Google I could only find items relating to WebForms, and the
> use of Session variables.
>
> Many thanks in advance,
>
>
> David McCormack
- Next message: Stoitcho Goutsev \(100\) [C# MVP]: "Re: how to get .net designer frame articles?"
- Previous message: pdavis68_at_hotmail.com: "Inconsistent access levels???"
- In reply to: David McCormack: "Global application variables in WinForms app"
- Next in thread: Jeff Mastry: "Re: Global application variables in WinForms app"
- Reply: Jeff Mastry: "Re: Global application variables in WinForms app"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|