Hi rockpune,
Here is a example you can run. Just create a new WindowsForms project and replace Program.cs with the following code.
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
static class Program
{
[STAThread]
static void Main()
{
Form form = new Form();
Label labelName = new Label();
labelName.Text = "Enter your name:";
labelName.Dock = DockStyle.Top;
Label labelBasic = new Label();
labelBasic.Text = "Enter the basic salary";
labelBasic.Dock = DockStyle.Top;
TextBox textboxName = new TextBox();
textboxName.Dock = DockStyle.Top;
TextBox textboxBasic = new TextBox();
textboxBasic.Dock = DockStyle.Top;
Label labelGrossSalary = new Label();
labelGrossSalary.Dock = DockStyle.Top;
Label labelNetSalary = new Label();
labelNetSalary.Dock = DockStyle.Top;
Button buttonCalculate = new Button();
buttonCalculate.Text = "Calculate";
buttonCalculate.Dock = DockStyle.Top;
buttonCalculate.Click += delegate(object sender, EventArgs e)
{
string strName = textboxName.Text;
float basic;
if (float.TryParse(textboxBasic.Text, out basic))
{
float net, gross;
Calculate(basic, out net, out gross);
labelGrossSalary.Text = gross.ToString();
labelNetSalary.Text = net.ToString();
}
else
{
MessageBox.Show(textboxBasic.Text + " is not a valid number");
}
};
form.Controls.AddRange(new Control[] { labelGrossSalary, labelNetSalary, buttonCalculate, textboxBasic, labelBasic, textboxName, labelName });
Application.Run(form);
}
static void buttonCalculate_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
static void Calculate(float basic, out float net, out float gross)
{
float da;
float hra;
float tax = 0f;
float pf;
pf = 0.08f * basic;
if (basic < 5000)
{
da = 0.3f * basic;
hra = 0.08f * basic;
}
else if ((basic >= 5000) && (basic < 10000))
{
da = 0.4f * basic;
hra = 0.1f * basic;
}
else
{
da = 0.5f * basic;
hra = 0.2f * basic;
}
gross = basic + da + hra;
net = gross - tax + pf;
}
}
}
Btw: you can tag your question with "forms" and you can tell us you want a form solution first... anyway this code seems to be homework, if I wasn't so bored today I wouldn't have created an example for such a "bad" question