Solved

change C# console app to windows form

Posted on 2011-02-14
3
406 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 85

Accepted Solution

by:
Mike Tomlinson earned 400 total points
Comment Utility
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 85

Expert Comment

by:Mike Tomlinson
Comment Utility
*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 100 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now