Solved

change C# console app to windows form

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SlingPlayer alternatives 1 35
Problem with Filesystemobject or .NET version 3 35
SQL Login 17 40
rest webservice call over https via c# 6 25
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

12 Experts available now in Live!

Get 1:1 Help Now