📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TESTINT
{
public partial class Form1 : Form
{
int op1;
int op2;
int result;
public Form1()
{
InitializeComponent();
}
//将输入的两个结果相乘
private void button1_Click(object sender, EventArgs e)
{
//定义三个数,分别接受用户输入的操作数和输出结果
try
{
op1 = Int32.Parse(textBox1.Text);
}
catch (System.FormatException)
{
MessageBox.Show("左边输入的不是一个double数");
return;
}
catch(System.OverflowException)
{
MessageBox.Show("你输入的左边的数超出了表示范围");
return;
}
try
{
op2=Int32.Parse(textBox2.Text);
}
catch(System.FormatException)
{
MessageBox.Show("右边输入的不是一个double数");
return;
}
catch(System.OverflowException)
{
MessageBox.Show("你输入的右边的数超出了表示的范围");
return;
}
try
{
result = checked(op1 * op2);
}
catch(System.OverflowException)
{
MessageBox.Show("结果超出了int表示范围");
return;
}
textBox3.Text=result.ToString();
}
//清除textbox1、textbox2、textbox3的值
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
//将接收的两个数相加
private void add_Click(object sender, EventArgs e)
{
try
{
op1 = Int32.Parse(textBox1.Text);
}
catch (System.FormatException)
{
MessageBox.Show("左边输入的不是double数");
return;
}
catch (System.OverflowException)
{
MessageBox.Show("输入的数超出了double数的范围");
return;
}
try
{
op2 = Int32.Parse(textBox2.Text);
}
catch (System.FormatException)
{
MessageBox.Show("右边输入的不是double数");
return;
}
catch (System.OverflowException)
{
MessageBox.Show("输入的数超出了double 数的范围");
return;
}
try
{
result = checked(op1 + op2);
}
catch (System.OverflowException)
{
MessageBox.Show("超出了double数的范围");
return;
}
textBox3.Text = result.ToString();
}
//将两个数相减
private void sub_Click(object sender, EventArgs e)
{
try
{
op1 = Int32.Parse(textBox1.Text);
}
catch (System.FormatException)
{
MessageBox.Show("左边输入的数不是doubel数");
}
catch (System.OverflowException)
{
MessageBox.Show("左边输入的数超出了double数的范围");
}
try
{
op2=Int32.Parse(textBox2.Text);
}
catch(System.FormatException)
{
MessageBox.Show("右边输入的不是一个double数");
return;
}
catch(System.OverflowException)
{
MessageBox.Show("你输入的右边的数超出了表示的范围");
return;
}
try
{
result = checked(op1 - op2);
}
catch(System.OverflowException)
{
MessageBox.Show("结果超出了int表示范围");
return;
}
textBox3.Text=result.ToString();
}
private void div_Click(object sender, EventArgs e)
{
try
{
op1 = Int32.Parse(textBox1.Text);
}
catch (System.FormatException)
{
MessageBox.Show("左边输入的数不是doubel数");
}
catch (System.OverflowException)
{
MessageBox.Show("左边输入的数超出了double数的范围");
}
try
{
op2 = Int32.Parse(textBox2.Text);
}
catch (System.FormatException)
{
MessageBox.Show("右边输入的不是一个double数");
return;
}
catch (System.OverflowException)
{
MessageBox.Show("你输入的右边的数超出了表示的范围");
return;
}
try
{
result = checked(op1 / op2);
}
catch (System.OverflowException)
{
MessageBox.Show("结果超出了int表示范围");
return;
}
textBox3.Text = result.ToString();
}
private void button6_Click(object sender, EventArgs e)
{
try
{
op1 = Int32.Parse(textBox1.Text);
}
catch (System.FormatException)
{
MessageBox.Show("左边输入的数不是doubel数");
}
catch (System.OverflowException)
{
MessageBox.Show("左边输入的数超出了double数的范围");
}
try
{
op2 = Int32.Parse(textBox2.Text);
}
catch (System.FormatException)
{
MessageBox.Show("右边输入的不是一个double数");
return;
}
catch (System.OverflowException)
{
MessageBox.Show("你输入的右边的数超出了表示的范围");
return;
}
try
{
result = checked(op1 % op2);
}
catch (System.OverflowException)
{
MessageBox.Show("结果超出了int表示范围");
return;
}
textBox3.Text = result.ToString();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -