473,418 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

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 1723
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Granade | last post by:
I'm looking for the best way to make a dataset available from multiple Windows forms. The dataset is created from an XML file. I have a main form (frmMain) that loads the dataset and reads the...
6
by: Gene Hubert | last post by:
I seem to be getting crazy results when I have multiple System.Windows.Forms.Timer objects in the same form running at the same time. When only one timer is running I get the expected behavior. ...
5
by: Samuel R. Neff | last post by:
When you have an unhandled exception in vb.net how do you view the exception information in the debugger? In C# the debugger creates a local variable that points to the exception and you can...
22
by: Brett Romero | last post by:
If my UI app uses three DLLs and two of those DLLs reference something named utilities.dll, does the UI app load utilities.dll twice or does the compiler recognize what is going on and load...
6
by: nsikkandar | last post by:
I created a Child Form and added several controls. One of the control is GroupBox1. When I want to change the access modifier property of the GroupBox1 FROM "Public WithEvents GroupBox3 As...
2
by: Joseph | last post by:
I am building a Windows application that has multiple forms. I am creating a dataset in one form and would like to know how to pass the results of that dataset to another form. Please provide some...
1
by: =?Utf-8?B?aXd1Y29tcHV0ZXJnZWVrMDU=?= | last post by:
I have encountered a frustrating problem with the VB environment, and I am afraid I need to re-install it on my system. I would like to know whether any of you have encountered the same problem or...
1
by: sap0321 | last post by:
This should be kindergarten stuff but for some reason I am having trouble with it. I do 99.9% web programming and this is the first windows app i've done in years - probably the first ever in C# ......
1
by: Autostrad | last post by:
Below; I have 2 classes (forms), Namely, "PrintOneEmployee" and "DeleteOne". In class "PrintOneEmployee"; I want to declare a variable with name of "fileName" to contain the name of the file...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.