using multiple sourcefiles

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2008
Posts: 47
Reputation: ctrl-alt-del is an unknown quantity at this point 
Solved Threads: 0
ctrl-alt-del ctrl-alt-del is offline Offline
Light Poster

using multiple sourcefiles

 
0
  #1
Mar 24th, 2009
Hello all! I have yet another question.

Since I'm making good progress in learning C# I'd like to learn some new stuff that I have been putting off and to clean up my code.

As such it seemed like a good idea to try and create a frontend for a program, in the way that you start the program, are presented with a bunch of buttons, and when you press one of the buttons it runs a specific file of code.

In a live example:
I would like to create a general calculationsprogram. It can calculate your BMI, from metric to imperial, between hexadecimal/binairy/decimal, stuff like that. When the program is run it greets you with a little choicescreen asking you what you want to calculate and stuff. For example: you press the BMI button and it hides the welcomescreen and loads the BMI part of the program.

No I'm not sure if I can use a class to load something like that. I would also like to split the program up in parts, so the BMI part has its own sourcefile.

Am I making any sense?

Anybody have any ideas? Questions are good too of course!

Thanks for reading!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,040
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 305
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: using multiple sourcefiles

 
0
  #2
Mar 24th, 2009
In your project solution explorer window right click the bold name and add a new Windows form. Fill it with what you want. Say it is called ExtraForm.
Now in your main form put the following code in a button click event:
ExtraForm.Show();
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 45
Reputation: bcasp is an unknown quantity at this point 
Solved Threads: 10
bcasp bcasp is offline Offline
Light Poster

Re: using multiple sourcefiles

 
0
  #3
Mar 24th, 2009
To answer you questions about the different source files, if you're using Visual Studio, each time you add a new component to your solution (as explained by ddanbe above), it is placed in its own physical code file in your solution's directory. So if you had 10 forms, you would expect to see 10 different source files that each contain one of your forms.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 47
Reputation: ctrl-alt-del is an unknown quantity at this point 
Solved Threads: 0
ctrl-alt-del ctrl-alt-del is offline Offline
Light Poster

Re: using multiple sourcefiles

 
0
  #4
Mar 24th, 2009
Originally Posted by bcasp View Post
To answer you questions about the different source files, if you're using Visual Studio, each time you add a new component to your solution (as explained by ddanbe above), it is placed in its own physical code file in your solution's directory. So if you had 10 forms, you would expect to see 10 different source files that each contain one of your forms.
This is indeed essentialy what I want, and I did know how to add components. I.. just don't know how to access them...

Say that I have the normal form1.cs file, and I add a BMI.cs file and write that file as though it was a single screen application. What command do I use for the button in form1 to access/load my BMI.cs code?

As for ddanbe, thanks for the hint on the .Show! I'm guessing .Hide hides the form until recalled?

Thanks for the help so far!
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,040
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 305
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: using multiple sourcefiles

 
0
  #5
Mar 24th, 2009
bcasp filled in something I forgot. Thanks!
Your guess on the Hide is right.
You make fields in the BMI form class you can acces (use property syntax) in your form1 class. (Assume you intantiated the BMI class via new) then you can use BMI.Myproperty; or do things like BMI.Myproperty = 123; etc.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 47
Reputation: ctrl-alt-del is an unknown quantity at this point 
Solved Threads: 0
ctrl-alt-del ctrl-alt-del is offline Offline
Light Poster

Re: using multiple sourcefiles

 
0
  #6
Mar 26th, 2009
To finish off this thread I'll add this:

What I needed was to know how to access another windows form file (BMI.cs).
I did this using:
  1. BMI classBMI = new BMI();
and later I could access classBMI just like my BMI.cs file

The .Show() and .Hide() were what I needed, so no additions there.

Thread solved I'd say.

Thanks for the help all!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum


Views: 640 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC