Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax, or more than that?

Status
Not open for further replies.

spearchucker

Programmer
Dec 23, 2002
3
0
0
US
I have a form, MainForm that I am using as the main GUI. I also have another form called StatsForm that I want to be able to control using MainForm's gui. The main thing I want to control is StatsForm's Hide() and Show() methods. I also have another file which holds some other various
classes and variables that are the basic workings of the programs, I call this class LORD. Now to my problem...In order for MainForm to be able to affect StatsForm I
made a reference to it in my LORD class' code. I wrote this:

StatsForm statsForm;
MainForm mainForm;

and in the constructor, I wrote this:

statsForm = new StatsForm;
mainForm = new MainForm;

So I am trying to use LORD.cs as the middle of the spiderweb so it has access to everything and can act as a middleman in lots of operations. First off, is my thinking correct, is there an easier way to do what I am
doing, I am new at this - should I organize my code and classes differently? All in one file perhaps, please give input. Secondly, my approach doesnt even work. Because I was using my LORD class as the center point, I had to declare it in all my forms like this:

LORD lord = new LORD;

This gave me many errors about nonstatic fields and missing namespaces! Am I missing something here, how do you guys make your programs containing multiple windows talk to eachother.

Please, perhaps use this as an opportunity to give a new kid with lots of motivation a short tutorial about design? :)
I would really appreciate it, I have so much drive, yet confusion of how to work it!

Brian Harris

 
Brian,

>LORD lord = new LORD;<

I would add () to the statement:

LORD lord = new LORD();

will give you less errors.

As for the other points in your question. What you want is possible and not too difficult But you will have to change the startpoint of your application, by changing the start method:

[STAThread]
static void Main()
{
Application.Run(new LORD());
}

Now your class LORD needs to be a WindowsForm or inherit from the Class AplicationContext. In your approach AplicationContext will probably give you more flexibility.

public class LORDS : System.Windows.Forms.AplicationContext

As for organizing your code, I would maintain each class in a separate .cs file.

HTH

Jan


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top