Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › C# form structure - accessing multiple forms/global variables?
New Posts  All Forums:Forum Nav:

C# form structure - accessing multiple forms/global variables?

post #1 of 3
Thread Starter 
Hi Guys,

In the process of my final year project I'm worried to go further as I think I'm doing it all wrong. My app is a 'network discovery tool' and I'm trying to leverage the power of PowerShell with a fancy C# U.I. (I havent touched programming in 2 years, but did a large Java module when I did).

Currently theres 3 forms, a login, main window and a PowerShell credentials window. I'm trying to access the PowerShell credential items from the main window.

1) Currently I'm creating all my methods in the main window form. Is that a problem or should I create them in 'program.cs' or is there another form/component/class I should create them in?

2) When it comes to accessing global variables I've read I can create a class just for it, not quite as easy at using 'global' in Java! Or should I use some central storage or a seperate file for all data like in the first question?

Many thanks!
post #2 of 3
Thread Starter 
As you can probably see I'm quite a noob, any help would be appreciated!
post #3 of 3
In Java you would have to put the variable as public and static in the class dedicated for global variables. Should work the same for C#.

For example, in Java, it would be like.
Code:
public class GlobalVars
{
    public static int varData = 3;
}


Teh computer
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q8400 MSI MS-7529 HIS icoolerIV 5750 1GB @ 822/1250 Corsair DDR2 2x2 gig 
Hard DriveOSMonitorPower
500 gig HDD SATA @ 7200 rpm Windows 7 32 bit / Ubuntu 10.10 32 bit AOC 22" WLED 1680x1050 Aywun 480W 
Case
Gigabyte gz-x4 
  hide details  
Reply
Teh computer
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q8400 MSI MS-7529 HIS icoolerIV 5750 1GB @ 822/1250 Corsair DDR2 2x2 gig 
Hard DriveOSMonitorPower
500 gig HDD SATA @ 7200 rpm Windows 7 32 bit / Ubuntu 10.10 32 bit AOC 22" WLED 1680x1050 Aywun 480W 
Case
Gigabyte gz-x4 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › C# form structure - accessing multiple forms/global variables?