VB.net 계산기 응용 프로그램을 만들었지 만 잘 작동하지만 5 + 7을 더하고 싶다고 말합니다. 그런 다음 응용 프로그램이 작동하면서 키보드에서 5를 누르면됩니다. 숫자 5가있는 버튼의 텍스트는 &5
이지만 키보드에서 +를 누르면 작동하지 않습니다. 계산기에서 + button
을 눌러야합니다.계산기 버튼을 누르지 않고 키보드 입력에서 계산기 입력 제공
내 추가 버튼이 클릭 이벤트를 처리하기 위해 설계 되었기 때문에 btn_add_Click
으로 생각합니다.이 응용 프로그램을 만들 수있는 방법은 계산기의 버튼을 누르지 않고도 키보드의 키를 눌러서 수행 할 수있는 방법입니다. computation.Here의 내 코드 :
Imports System.Math
Public Class Form1
Private isFirstExist As Boolean
Private inputOperator As String
Private secondNum As Decimal
Private firstNum As Decimal
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtCalc.TextChanged
End Sub
Private Sub btn_zero_Click(sender As System.Object, e As System.EventArgs) Handles btn_zero.Click
removeFrontZero(0)
End Sub
Private Sub btn_one_Click(sender As System.Object, e As System.EventArgs) Handles btn_one.Click
removeFrontZero(1)
End Sub
Private Sub btn_two_Click(sender As System.Object, e As System.EventArgs) Handles btn_two.Click
removeFrontZero(2)
End Sub
Private Sub btn_clear_Click(sender As System.Object, e As System.EventArgs) Handles btn_clear.Click
txtCalc.Clear()
txtCalc.Text = "0"
End Sub
'Remove zero which is at the start
Public Sub removeFrontZero(ByVal digit As Integer)
If txtCalc.Text = "0" Then
txtCalc.Text = CStr(digit)
Else
txtCalc.Text &= digit
End If
End Sub
Private Sub btn_add_Click(sender As System.Object, e As System.EventArgs) Handles btn_add.Click
inputOperator = "+"
isFirst()
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
isFirstExist = False
End Sub
Private Sub btn_equal_Click(sender As System.Object, e As System.EventArgs) Handles btn_equal.Click
If isFirstExist Then
secondNum = CType(txtCalc.Text, Decimal)
End If
'Calculating the result
Dim result As Decimal = calculate(firstNum, secondNum, inputOperator)
txtCalc.Text = result.ToString()
isFirstExist = False
End Sub
Private Function calculate(ByVal num1 As Decimal, ByVal num2 As Decimal, ByVal inputOp As String) As Decimal
Dim output As Decimal
firstNum = num1
secondNum = num2
Select Case inputOp
Case "+"
output = num1 + num2
Case "-"
output = num1 - num2
Case "/"
Dim value As Decimal
Try
isFirst()
value = (num1/num2)
Catch ex As DivideByZeroException
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK)
End Try
output = value
Case "*"
output = num1 * num2
Case "Mod"
output = (num1 Mod num2)
Case "^"
output = CDec(Math.Pow(num1, num2))
End Select
Return output
End Function
Private Sub isFirst()
If isFirstExist = False Then
firstNum = CType(txtCalc.Text, Decimal)
isFirstExist = True
txtCalc.Text = "0"
End If
End Sub
숫자 버튼으로했던 것과 똑같은 + 버튼 (즉, 키보드 가속기 만들기 +)을 사용하면 어떨까요? –
하지만 그때 추가 작업이 수행되지 않습니다 –