Solved

change C# console app to windows form

Posted on 2011-02-14
3
411 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 400 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 100 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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