📄 form1.cs
字号:
//
this.button4.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button4.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button4.Location = new System.Drawing.Point(176, 48);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(40, 32);
this.button4.TabIndex = 9;
this.button4.Text = "/";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button5.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button5.Location = new System.Drawing.Point(8, 96);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(40, 32);
this.button5.TabIndex = 10;
this.button5.Text = "4";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button6.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button6.Location = new System.Drawing.Point(64, 96);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(40, 32);
this.button6.TabIndex = 11;
this.button6.Text = "5";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button7
//
this.button7.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button7.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button7.Location = new System.Drawing.Point(120, 96);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(40, 32);
this.button7.TabIndex = 12;
this.button7.Text = "6";
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// button8
//
this.button8.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button8.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button8.Location = new System.Drawing.Point(176, 96);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(40, 32);
this.button8.TabIndex = 13;
this.button8.Text = "*";
this.button8.Click += new System.EventHandler(this.button8_Click);
//
// button9
//
this.button9.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button9.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button9.Location = new System.Drawing.Point(8, 144);
this.button9.Name = "button9";
this.button9.Size = new System.Drawing.Size(40, 32);
this.button9.TabIndex = 14;
this.button9.Text = "1";
this.button9.Click += new System.EventHandler(this.button9_Click);
//
// button10
//
this.button10.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button10.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button10.Location = new System.Drawing.Point(64, 144);
this.button10.Name = "button10";
this.button10.Size = new System.Drawing.Size(40, 32);
this.button10.TabIndex = 15;
this.button10.Text = "2";
this.button10.Click += new System.EventHandler(this.button10_Click);
//
// button11
//
this.button11.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button11.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button11.Location = new System.Drawing.Point(120, 144);
this.button11.Name = "button11";
this.button11.Size = new System.Drawing.Size(40, 32);
this.button11.TabIndex = 16;
this.button11.Text = "3";
this.button11.Click += new System.EventHandler(this.button11_Click);
//
// button12
//
this.button12.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button12.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button12.Location = new System.Drawing.Point(176, 144);
this.button12.Name = "button12";
this.button12.Size = new System.Drawing.Size(40, 32);
this.button12.TabIndex = 17;
this.button12.Text = "-";
this.button12.Click += new System.EventHandler(this.button12_Click);
//
// button13
//
this.button13.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button13.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button13.Location = new System.Drawing.Point(8, 192);
this.button13.Name = "button13";
this.button13.Size = new System.Drawing.Size(40, 32);
this.button13.TabIndex = 18;
this.button13.Text = "0";
this.button13.Click += new System.EventHandler(this.button13_Click);
//
// button14
//
this.button14.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button14.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button14.Location = new System.Drawing.Point(64, 192);
this.button14.Name = "button14";
this.button14.Size = new System.Drawing.Size(40, 32);
this.button14.TabIndex = 19;
this.button14.Text = ".";
this.button14.Click += new System.EventHandler(this.button14_Click);
//
// button15
//
this.button15.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button15.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button15.Location = new System.Drawing.Point(120, 192);
this.button15.Name = "button15";
this.button15.Size = new System.Drawing.Size(40, 32);
this.button15.TabIndex = 20;
this.button15.Text = "=";
this.button15.Click += new System.EventHandler(this.button15_Click);
//
// button16
//
this.button16.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button16.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button16.Location = new System.Drawing.Point(176, 192);
this.button16.Name = "button16";
this.button16.Size = new System.Drawing.Size(40, 32);
this.button16.TabIndex = 21;
this.button16.Text = "+";
this.button16.Click += new System.EventHandler(this.button16_Click);
//
// button17
//
this.button17.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button17.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button17.Location = new System.Drawing.Point(8, 240);
this.button17.Name = "button17";
this.button17.Size = new System.Drawing.Size(208, 24);
this.button17.TabIndex = 22;
this.button17.Text = "Clear";
this.button17.Click += new System.EventHandler(this.button17_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 16);
this.BackColor = System.Drawing.SystemColors.ControlText;
this.ClientSize = new System.Drawing.Size(224, 277);
this.Controls.Add(this.button17);
this.Controls.Add(this.button16);
this.Controls.Add(this.button15);
this.Controls.Add(this.button14);
this.Controls.Add(this.button13);
this.Controls.Add(this.button12);
this.Controls.Add(this.button11);
this.Controls.Add(this.button10);
this.Controls.Add(this.button9);
this.Controls.Add(this.button8);
this.Controls.Add(this.button7);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.Screen);
this.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "计算器";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
//---------------------------- 0~9 数字键 -----------------------------
private void button13_Click(object sender, System.EventArgs e)
{ // 0键
if( Screen.Text != "0" && Screen.Text.Length < 15 )
TypeInNumber("0");
}
private void button9_Click(object sender, System.EventArgs e)
{
TypeInNumber("1");
}
private void button10_Click(object sender, System.EventArgs e)
{
TypeInNumber("2");
}
private void button11_Click(object sender, System.EventArgs e)
{
TypeInNumber("3");
}
private void button5_Click(object sender, System.EventArgs e)
{
TypeInNumber("4");
}
private void button6_Click(object sender, System.EventArgs e)
{
TypeInNumber("5");
}
private void button7_Click(object sender, System.EventArgs e)
{
TypeInNumber("6");
}
private void button1_Click(object sender, System.EventArgs e)
{
TypeInNumber("7");
}
private void button2_Click(object sender, System.EventArgs e)
{
TypeInNumber("8");
}
private void button3_Click(object sender, System.EventArgs e)
{
TypeInNumber("9");
}
//======================================================================
private void button14_Click(object sender, System.EventArgs e)
{ // 小数点
foreach ( char point in Screen.Text ) //遍历检查当前是否为小数。但一个bug是不能在其他运算得出结果后直接按“.”进行“0.”输入
{
if( point == '.' )
{
IsReal = true;
break;
}
else
{
IsReal = false;
}
}
if( !IsReal )
{
if( Screen.Text != "0" )
{
TypeInNumber(".");
}
else
{
Screen.Text = "";
TypeInNumber("0.");
}
IsReal = true;
}
}
private void button15_Click(object sender, System.EventArgs e)
{
ShowResult();
}
private void button4_Click(object sender, System.EventArgs e)
{ //除
Operate( "div" );
}
private void button16_Click(object sender, System.EventArgs e)
{ //加
Operate( "add" );
}
private void button8_Click(object sender, System.EventArgs e)
{ //乘
Operate( "mul" );
}
private void button12_Click(object sender, System.EventArgs e)
{ //减
Operate( "minus" );
}
private void button17_Click(object sender, System.EventArgs e)
{ // 清空
Clear();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -