namespace WindowsFormsApplication16
{
class Compute
{
public static void cs(int o,int p,out int a,out int b) {
a = o / p;
b = o % p;
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i = Convert.ToInt32(textBox1.Text);
int j = Convert.ToInt32(textBox2.Text);
//判断除数是否为零
if (j == 0)
{
MessageBox.Show("除数不能为零,请重新输入", "错误警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
textBox1.Clear(); textBox2.Clear();
textBox2.Focus();
}
else {
int n,m;
Compute.cs(i,j,out n,out m);
textBox3.Text = n.ToString();
textBox4.Text = m.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Focus();
textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear();
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
c# 求商与余数,余数为零时弹窗警告。
最新推荐文章于 2024-03-30 12:23:10 发布