vb.net简单的计算器实现
1首先我们需要把控件都摆好.
2处理0~9按钮事件
代码语言:javascript
复制
'按钮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</code></pre></div></div><p>3处理加减乘除按钮事件</p><div class="rno-markdown-code"><div class="rno-markdown-code-toolbar"><div class="rno-markdown-code-toolbar-info"><div class="rno-markdown-code-toolbar-item is-type"><span class="is-m-hidden">代码语言:</span>javascript</div></div><div class="rno-markdown-code-toolbar-opt"><div class="rno-markdown-code-toolbar-copy"><i class="icon-copy"></i><span class="is-m-hidden">复制</span></div></div></div><div class="developer-code-block"><pre class="prism-token token line-numbers language-javascript"><code class="language-javascript" style="margin-left:0">'按钮加减乘除
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</code></pre></div></div><p>4处理=按钮事件</p><div class="rno-markdown-code"><div class="rno-markdown-code-toolbar"><div class="rno-markdown-code-toolbar-info"><div class="rno-markdown-code-toolbar-item is-type"><span class="is-m-hidden">代码语言:</span>javascript</div></div><div class="rno-markdown-code-toolbar-opt"><div class="rno-markdown-code-toolbar-copy"><i class="icon-copy"></i><span class="is-m-hidden">复制</span></div></div></div><div class="developer-code-block"><pre class="prism-token token line-numbers language-javascript"><code class="language-javascript" style="margin-left:0">'按钮等于号
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</code></pre></div></div><p><strong>有需要源码的小伙伴可以联系我。也欢迎其他小伙伴留言交流学习</strong></p>