469,347 Members | 20,428 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,347 developers. It's quick & easy.

A variable to use and change on multiple forms in 1 windows app

This is a C# 2005 project:

I'm struggling to figure how to make a variable accessible and changeable in
several forms in a windows application..

It's only a int variable which is set when the program loads, and this must
be accessible from any form within the application, and I also need to be
able to change it from any form.
Any hints or samples on how I can do this?

Thanks!
Svein Erik
Jul 17 '06 #1
4 1589
"Svein Erik" <Sv*******@discussions.microsoft.comwrote in message
news:27**********************************@microsof t.com...
This is a C# 2005 project:

I'm struggling to figure how to make a variable accessible and changeable
in
several forms in a windows application..

It's only a int variable which is set when the program loads, and this
must
be accessible from any form within the application, and I also need to be
able to change it from any form.
Any hints or samples on how I can do this?
Put this int in any class like this

class ABC
{
public static int MyInt;
}

then use it like this

ABC.MyInt = 5;

You can also create property set and get for it if you like.
>
Thanks!
Svein Erik

Jul 17 '06 #2


"Michael C" wrote:
"Svein Erik" <Sv*******@discussions.microsoft.comwrote in message
news:27**********************************@microsof t.com...
This is a C# 2005 project:

I'm struggling to figure how to make a variable accessible and changeable
in
several forms in a windows application..

It's only a int variable which is set when the program loads, and this
must
be accessible from any form within the application, and I also need to be
able to change it from any form.
Any hints or samples on how I can do this?

Put this int in any class like this

class ABC
{
public static int MyInt;
}

then use it like this

ABC.MyInt = 5;

You can also create property set and get for it if you like.

Thanks!
Svein Erik

Thanks!
I went for the property set, and it works like a charm :)
But now i stumbled upon the next problem:

When i have 2 property sets; Track1 and Track2. How can i use the track that
the user selects on load?
If the user selects Track2, properties for Track2 is to be loaded:
.....properties.Track2.Default....
How can I set the Track2 text manually?

Thank you!
Jul 17 '06 #3
Hi,

You will have to either wrap the class or use a third property

class ABC
{
public static int MyInt;

public static string GetValue{ get{ if (MyInt == 1 ) return "track 1"; else
return "track2"; } }
}
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Svein Erik" <Sv*******@discussions.microsoft.comwrote in message
news:C7**********************************@microsof t.com...
>

"Michael C" wrote:
>"Svein Erik" <Sv*******@discussions.microsoft.comwrote in message
news:27**********************************@microso ft.com...
This is a C# 2005 project:

I'm struggling to figure how to make a variable accessible and
changeable
in
several forms in a windows application..

It's only a int variable which is set when the program loads, and this
must
be accessible from any form within the application, and I also need to
be
able to change it from any form.
Any hints or samples on how I can do this?

Put this int in any class like this

class ABC
{
public static int MyInt;
}

then use it like this

ABC.MyInt = 5;

You can also create property set and get for it if you like.
>
Thanks!
Svein Erik

Thanks!
I went for the property set, and it works like a charm :)
But now i stumbled upon the next problem:

When i have 2 property sets; Track1 and Track2. How can i use the track
that
the user selects on load?
If the user selects Track2, properties for Track2 is to be loaded:
....properties.Track2.Default....
How can I set the Track2 text manually?

Thank you!

Jul 17 '06 #4
Hi, thanks for the reply!

But I mean, how can i use a string variable in the method that gets values
from a specified .settings file.

On load, the user selects which track he wants, if he selects track 2, then
the method will look like this: ...properties.Track2.Default.THEVALUE, and on
track 1 like this: properties.Track1.Default.THEVALUE.

It's the "string" Track1 and Track2 i want to replace with a variable that
is selected from the user.

Thank you :)

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

You will have to either wrap the class or use a third property

class ABC
{
public static int MyInt;

public static string GetValue{ get{ if (MyInt == 1 ) return "track 1"; else
return "track2"; } }
}
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Svein Erik" <Sv*******@discussions.microsoft.comwrote in message
news:C7**********************************@microsof t.com...


"Michael C" wrote:
"Svein Erik" <Sv*******@discussions.microsoft.comwrote in message
news:27**********************************@microsof t.com...
This is a C# 2005 project:

I'm struggling to figure how to make a variable accessible and
changeable
in
several forms in a windows application..

It's only a int variable which is set when the program loads, and this
must
be accessible from any form within the application, and I also need to
be
able to change it from any form.
Any hints or samples on how I can do this?

Put this int in any class like this

class ABC
{
public static int MyInt;
}

then use it like this

ABC.MyInt = 5;

You can also create property set and get for it if you like.


Thanks!
Svein Erik

Thanks!
I went for the property set, and it works like a charm :)
But now i stumbled upon the next problem:

When i have 2 property sets; Track1 and Track2. How can i use the track
that
the user selects on load?
If the user selects Track2, properties for Track2 is to be loaded:
....properties.Track2.Default....
How can I set the Track2 text manually?

Thank you!


Jul 18 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Gene Hubert | last post: by
22 posts views Thread by Brett Romero | last post: by
2 posts views Thread by Joseph | last post: by
1 post views Thread by =?Utf-8?B?aXd1Y29tcHV0ZXJnZWVrMDU=?= | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.