Dear Sir,
I'm Trying use event In the textbox payment and discount but can't slide the arrow keyboard in vb.net label.
Is there something wrong with my code?
So the problem is that I can't change one of the value characters so the solution is to use the backspace keyboard and then retype it.
Link video result code
Please Guide me
Thanks
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LabelTotalvalue.Text = 1121000.ToString("N0")
txtDiscount.Text = 0.ToString("N0")
txtPayment.Text = 0.ToString("N0")
LabelChange.Text = (0 - 1121000).ToString("N0")
End Sub
Private Sub Textbox(sender As Object, e As EventArgs) Handles txtPayment.TextChanged, txtDiscount.TextChanged
Dim payment As Double = 0
Dim discount As Double = 0
If Not String.IsNullOrEmpty(txtPayment.Text) OrElse Not String.IsNullOrEmpty(txtDiscount.Text) Then
Double.TryParse(txtPayment.Text, payment)
Double.TryParse(txtDiscount.Text, discount)
LabelChange.Text = ((discount + payment) - Convert.ToDouble(LabelTotalvalue.Text)).ToString("N0")
End If
End Sub
Private Sub OnText_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPayment.KeyPress, txtDiscount.KeyPress
If Not Char.IsControl(e.KeyChar) AndAlso Not Char.IsDigit(e.KeyChar) Then
e.Handled = True
End If
End Sub
Private Sub txtPayment_KeyUp(sender As Object, e As KeyEventArgs) Handles txtPayment.KeyUp
txtPayment.Text = txtPayment.Text.Replace(",", "")
Dim discount As Double = 0
Dim payment As Double = 0
If Not String.IsNullOrEmpty(txtPayment.Text) Then
Double.TryParse(txtPayment.Text, payment)
Double.TryParse(txtDiscount.Text, discount)
LabelChange.Text = ((discount + payment) - Convert.ToDouble(LabelTotalvalue.Text)).ToString("N0")
txtPayment.Text = payment.ToString("N0")
txtPayment.[Select](txtPayment.Text.Length, 0)
End If
End Sub
Private Sub txtDiscount_KeyUp(sender As Object, e As KeyEventArgs) Handles txtDiscount.KeyUp
txtDiscount.Text = txtDiscount.Text.Replace(",", "")
Dim discount As Double = 0
Dim payment As Double = 0
If Not String.IsNullOrEmpty(txtDiscount.Text) Then
Double.TryParse(txtPayment.Text, payment)
Double.TryParse(txtDiscount.Text, discount)
LabelChange.Text = ((discount + payment) - Convert.ToDouble(LabelTotalvalue.Text)).ToString("N0")
txtDiscount.Text = discount.ToString("N0")
txtDiscount.[Select](txtDiscount.Text.Length, 0)
End If
End Sub
End Class