RFB  - C # 2008 / 2010 Tutorials

 

Index

C # 2008 / 2010

Lesson 9: Simple Payroll Calculator

 

This tutorial will show you how to make a simple Payroll Calculator

Open C# 2008 / 2010

C Sharp Hello World

Click on New Project

Click on Windows Form Application

Then name your project and click ok

Drag 2 labels to the form from the ControlBox

Change the labels text properties to : Hours , Pay Rate

Then add 2 textboxes to the form :

Then add a button and change it's text property to Calculate:

After designing the form, let's add the code to the program.

The only code we are adding to the program is when calculate button is clicked:

Double click on Calculate button. This will take you to the code page:

private void button1_Click(object sender, EventArgs e)

        {

 

        }

Before we do the calculations, the program will make sure that there is data entered in text boxes:

private void button1_Click(object sender, EventArgs e)

        {

            if (textBox1.Text.Length < 1)

                MessageBox.Show("Please Enter a value in Hours Field");

            else if (textBox2.Text.Length < 1)

                MessageBox.Show("Please Enter a value in Pay Rate Field");

 

        }

 Let's try the program now by hitting F5 key:

Notice that the program will make sure that the fields are filled with data.

Let's add the calculations code:

private void button1_Click(object sender, EventArgs e)

        {

            if (textBox1.Text.Length < 1)

                MessageBox.Show("Please Enter a value in Hours Field");

            else if (textBox2.Text.Length < 1)

                MessageBox.Show("Please Enter a value in Pay Rate Field");

            else

            {

                double hours = Convert.ToDouble(textBox1.Text);

                double rate = Convert.ToDouble(textBox2.Text);

 

                MessageBox.Show("Your Gross Pay is $" + (rate * hours));

            }

 

        }

Test the program:

 

 

 

 

 

 

Lesson 10: Average Score Calculator