0

I am a newbie programmer who is now developing application on C# with Visual Studio 2010 and many forms, so i am interested is it possible to set some global variables to use them in all forms ? Simple example, i have 10 forms, all of them are connecting to MySQL database, so it is not really smart to set 10 times database name and password when in ideal i can set in once and then use everywhere, i can't find answer to this question in google, so maybe somebody can help me here? Is it possible?

Itsmeromka
  • 3,621
  • 9
  • 46
  • 79

2 Answers2

6

Create a base class for your form, something that inherits from Form. Initialize the shared values there, to be accessible by the inheriting forms.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
2

There are few ways you can solve this.

  • First you can use settings.
  • Second you could use web.config (not sure if this works in forms)
  • Third option is to create a static class that hold your variables.
Icy Creature
  • 1,875
  • 2
  • 28
  • 53