Public Class Form1
Dim num1 As Double = 0 '第一个操作数
Dim num2 As Double = 0 '第二个操作数
Dim op As Char = " " '当前操作符
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
'将数字键的文本添加到文本框中
TextBox1.Text += CType(sender, Button).Text
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
'将数字键的文本添加到文本框中
TextBox1.Text += CType(sender, Button).Text
End Sub
Private Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
'将数字键的文本添加到文本框中
TextBox1.Text += CType(sender, Button).Text
End Sub
Private Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
'将数字键的文本添加到文本框中
TextBox1.Text += CType(sender, Button).Text
End Sub
Private Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button5.Click
'将数字键的文本添加到文本框中
TextBox1.Text += CType(sender, Button).Text
End Sub
Private Sub Button6_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button6.Click
'将数字键的文本添加到文本框中
TextBox1.Text += CType(sender, Button).Text
End Sub
Private Sub Button7_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button7.Click
'将数字键的文本添加到文本框中
TextBox1.Text += CType(sender, Button).Text
End Sub
Private Sub Button8_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button8.Click
'将数字键的文本添加到文本框中
TextBox1.Text += CType(sender, Button).Text
End Sub
Private Sub Button9_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button9.Click
'将数字键的文本添加到文本框中
TextBox1.Text += CType(sender, Button).Text
End Sub
Private Sub Button10_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button10.Click
'将数字键的文本添加到文本框中
TextBox1.Text += CType(sender, Button).Text
End Sub
Private Sub Button11_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button11.Click
'保存第一个操作数和当前操作符,并清空文本框
num1 = CDbl(TextBox1.Text)
op = CType(sender, Button).Text.Chars(0)
TextBox1.Clear()
End Sub
Private Sub Button12_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button12.Click
'保存第一个操作数和当前操作符,并清空文本框
num1 = CDbl(TextBox1.Text)
op = CType(sender, Button).Text.Chars(0)
TextBox1.Clear()
End Sub
Private Sub Button13_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button13.Click
'保存第一个操作数和当前操作符,并清空文本框
num1 = CDbl(TextBox1.Text)
op = CType(sender, Button).Text.Chars(0)
TextBox1.Clear()
End Sub
Private Sub Button14_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button14.Click
'保存第一个操作数和当前操作符,并清空文本框
num1 = CDbl(TextBox1.Text)
op = CType(sender, Button).Text.Chars(0)
TextBox1.Clear()
End Sub
Private Sub Button15_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button15.Click
'执行计算并显示结果
num2 = CDbl(TextBox1.Text)
Dim result As Double = 0
Select Case op
Case "+"
result = num1 + num2
Case "-"
result = num1 - num2
Case "*"
result = num1 * num2
Case "/"
If num2 <> 0 Then
result = num1 / num2
Else
MessageBox.Show("除数不能为零!")
End If
End Select
TextBox1.Text = result.ToString()
End Sub
Private Sub Button16_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button16.Click
'清空文本框和操作数
TextBox1.Clear()
num1 = 0
num2 = 0
op = " "
End Sub
Private Sub Button17_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button17.Click
'删除最后一位字符
If TextBox1.Text.Length > 0 Then
TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1)
End If
End Sub
End Class