Re: Global application variables in WinForms app

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

pdavis68_at_hotmail.com
Date: 05/31/04


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



Relevant Pages

  • Re: Global application variables in WinForms app
    ... Future maintenance programmers will appreciate your ... > Use a class with static members. ... > class Globals ... >>mean override routines in every single form. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Domian local group versus Domain admin group
    ... Opinions differ as to when use of domain global vs domain local ... as globals can contain only objects from ... need to change the members). ... > "Roger Abell" wrote in message ...
    (microsoft.public.win2000.security)
  • How to make global data thread safe ? Please Help...
    ... I have a public static class with public static members (different ... I have a worker function which is called asynchronously (so that there ... will write the entire set of globals when given control through a GUI ... accessing any of the global members and the writer function is called, ...
    (microsoft.public.dotnet.framework)
  • Re: How do I do this? (eval() on the left hand side)
    ... Nick Coghlan wrote: ... could you please comment on why you say this about globals()? ... I'm a devoted follower of the Pythonic principle of 'explicit is better ... used this->name to reference C++ members despite the fact that 'this' ...
    (comp.lang.python)
  • Re: Should Globally Needed Objects be Members in Main Frame, Application, or be Global?
    ... maintenance in your work environment. ... I do like the g_ syntax for globals, ... but I'd assume those would be statically global, not members of a class. ...
    (microsoft.public.vc.mfc)