Global class

P

pOtrek

I'm new to c# and visual studio, previously i've been using borland
compilers like Delphi, so i have 2 questions:

I want to do class that every other class/forms have access to (i want
to store program configuration there). How should i do it (or where
sould i declare variable that points to this class) without using
static proprties ??

My second problem is how to get access to global methods from main
form class (class that starts the program) from other classes/forms

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
M

msnews.microsoft.com

If you have a MainForm class

Then whenever you call a ChildForm pass on the MainForm Pointer like this


ChildForm oChildForm = new ChildForm()
oChildForm.PerformHandShake(this)


In the ChildForm Class

Define as follows

MainForm MainFormPointer ;

void PerformHandShake(MainForm mainformptr)
{
this.MainFormPointer = mainformptr ;
}

From this point onwards you will have all the access to the MainForm
variables and methods from this ChildForm.

Hope this helps


Anand
 
T

Tim Jarvis

pOtrek said:
I'm new to c# and visual studio, previously i've been using borland
compilers like Delphi, so i have 2 questions:

I want to do class that every other class/forms have access to (i want
to store program configuration there). How should i do it (or where
sould i declare variable that points to this class) without using
static proprties ??

My second problem is how to get access to global methods from main
form class (class that starts the program) from other classes/forms

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Another option for you is for you to create your Options class as a
singleton (google is your friend here for some good example code)

Then rather than keeping track of a global variable you just call the
static instance (or whatever you call it) method to get your config
class instance...

string connString = Config.Instance.GetSomeConnectionString();

Regards Tim Jarvis.
 

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