vb.net简单的计算器实现
效果图
1首先我们需要把控件都摆好.
2处理0~9按钮事件
'按钮0~9
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If stat = 1 Then
TextBox1.Text = 0
stat = 0
End If
If TextBox1.Text = "0" Then
TextBox1.Text = "1"
Else
TextBox1.Text = TextBox1.Text + "1"
End If
End Sub
3处理加减乘除按钮事件
'按钮加减乘除
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
sign = "+"
one = TextBox1.Text
TextBox1.Text = 0
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
sign = "-"
one = TextBox1.Text
TextBox1.Text = 0
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
sign = "*"
one = TextBox1.Text
TextBox1.Text = 0
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
sign = "/"
one = TextBox1.Text
TextBox1.Text = 0
End Sub
4处理=按钮事件
'按钮等于号
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
two = TextBox1.Text
If sign = "+" Then
add()
End If
If sign = "-" Then
minus()
End If
If sign = "*" Then
multiply()
End If
If sign = "/" Then
divide()
End If
End Sub
有需要源码的小伙伴可以联系我。也欢迎其他小伙伴留言交流学习
q:2316773638
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/2871.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...