Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

change C# console app to windows form

Posted on 2011-02-14
3
Medium Priority
?
427 Views
Last Modified: 2012-05-11
not school work-
can i turn this console C# program into a program using a windows form?
if possible- any first ideas as to how to go about it?
program asks for salaries-
then sums them up with array and a for loop-
i have a more complicated program to convert- but do not understand how to have for loop and array in a gui form
thank you
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test1
{
    class Program
    {
        static void Main(string[] args)
        {
            
            int i;
            int[] salary = new int[10];
            int sumofsalary = 0;
            
            for (i = 0;i <=4; i++)
            {
                Console.WriteLine("enter salary of Employee: {0}", i + 1);
                salary[i] = Int32.Parse(Console.ReadLine());
            }
            for (i = 0; i <= 4; i++)
            {
                sumofsalary = sumofsalary + salary[1];
            }
            Console.WriteLine("total salary given to employees is = " + sumofsalary);

Open in new window

0
Comment
Question by:davetough
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1600 total points
ID: 34891775
The Console app stops at ReadLine() and waits for input...giving just one path thru the app.

In a WinForms app you'd place a TextBox on the Form for entry, and a Button to initiate the action.  You could use a Label to display the results.

When the button is pressed it generates a Click() event that the Form subscribes to.  So you'd put the "meat" of the code into the Click() handler and then update the Label with the result...
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 34891804
*You'd have to make a design-decision, supply ONE TextBox and track the number of entries with each Button click.
...or use multiple TextBoxes, one for each slot in the array.
...or use a DataGrid type control instead.
0
 
LVL 7

Assisted Solution

by:dimaj
dimaj earned 400 total points
ID: 34892052
What you'll have to do is:
1) Create a form that would prompt for the values you need to compute
2) Then, from your main, you'll make these calls:
Form myfrm = new MyForm(); // where MyForm is the name of your form from step 1
myfrm.ShowDialog();

Until you physically close the form, you app will not quit.

If you want to pass in your command line arguments to the form, make sure that your form's constructor can handle your arguments and then just call new MyForm (args);

Hope this helps.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month21 days, 7 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question