943,987 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 1704
  • C# RSS
Mar 24th, 2009
0

using multiple sourcefiles

Expand Post »
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!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
ctrl-alt-del is offline Offline
65 posts
since Jul 2008
Mar 24th, 2009
0

Re: using multiple sourcefiles

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();
Reputation Points: 2035
Solved Threads: 645
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Mar 24th, 2009
0

Re: using multiple sourcefiles

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.
Reputation Points: 23
Solved Threads: 10
Light Poster
bcasp is offline Offline
45 posts
since Apr 2008
Mar 24th, 2009
0

Re: using multiple sourcefiles

Click to Expand / Collapse  Quote originally posted by bcasp ...
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!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
ctrl-alt-del is offline Offline
65 posts
since Jul 2008
Mar 24th, 2009
0

Re: using multiple sourcefiles

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.
Reputation Points: 2035
Solved Threads: 645
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Mar 26th, 2009
0

Re: using multiple sourcefiles

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:
C# Syntax (Toggle Plain Text)
  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!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
ctrl-alt-del is offline Offline
65 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: LINQ question
Next Thread in C# Forum Timeline: Int32 to float





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC