When I click the buttons nothing happens. Can't figure out why.
Code:
using System;
using System.Windows.Forms;
public class frmMain : Form
{
private TextBox txtOperand1;
private Label txtResult;
private Button btnCalc;
private Button btnExit;
private Label label1;
#region Windows code
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.txtOperand1 = new System.Windows.Forms.TextBox();
this.txtResult = new System.Windows.Forms.Label();
this.btnCalc = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label1.Location = new System.Drawing.Point(24, 19);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(100, 23);
this.label1.TabIndex = 0;
this.label1.Text = "enter temp";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtOperand1
//
this.txtOperand1.Location = new System.Drawing.Point(144, 21);
this.txtOperand1.Name = "txtOperand1";
this.txtOperand1.Size = new System.Drawing.Size(100, 20);
this.txtOperand1.TabIndex = 1;
//
// txtResult
//
this.txtResult.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.txtResult.Location = new System.Drawing.Point(24, 64);
this.txtResult.Name = "txtResult";
this.txtResult.Size = new System.Drawing.Size(220, 23);
this.txtResult.TabIndex = 2;
//
// btnCalc
//
this.btnCalc.Location = new System.Drawing.Point(24, 121);
this.btnCalc.Name = "btnCalc";
this.btnCalc.Size = new System.Drawing.Size(126, 23);
this.btnCalc.TabIndex = 3;
this.btnCalc.Text = "click here to calculate";
this.btnCalc.UseVisualStyleBackColor = true;
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(169, 121);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(75, 23);
this.btnExit.TabIndex = 4;
this.btnExit.Text = "exit";
this.btnExit.UseVisualStyleBackColor = true;
//
// frmMain
//
this.ClientSize = new System.Drawing.Size(284, 167);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnCalc);
this.Controls.Add(this.txtResult);
this.Controls.Add(this.txtOperand1);
this.Controls.Add(this.label1);
this.Name = "frmMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Temp Convertor";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public frmMain()
{
InitializeComponent();
txtResult.Visible = false;
}
public static void Main()
{
frmMain main = new frmMain();
Application.Run(main);
}
private void btnCalc_Click(object sender, EventArgs e)
{
bool flag;
double operand1;
double answer;
flag = double.TryParse(txtOperand1.Text, out operand1);
if (flag == false)
{
MessageBox.Show("Please enter in a correct temp", "Input Eror");
txtOperand1.Focus();
return;
}
answer = 5.0 / 9.0 * (operand1 - 32);
txtResult.Text = operand1.ToString() + "is" + answer.ToString() + "Celsius";
txtResult.Visible = true;
}
private void btnExit_Click(object sender, EventArgs e)
{
Close();
}
}