Community discussion forum

How to shift the character at the front of the integer ??

Tags: India
  • 1 year ago

    HI

    I am making a Currency user control.

    What I needed to do is when I press "-" ( minus ) from keyboard in the textbox, the minus should appear at the front of  the integer  no matter when I press it. For example, I have typed a number in the textbox like 1,342,23   Now when i press " - " , it should appear at the front, like   -1,342,23.

    How can I do this ?

  • 1 year ago

    Hello,

    You can try the given code. But you may have to manipulate according to your requirement. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

    If Not IsNumeric(e.KeyChar) Then

    e.Handled = True

    If Asc(e.KeyChar) = 45 And InStr(TextBox1.Text, e.KeyChar) = 0 Then

    Dim str As String

    str = String.Concat(e.KeyChar.ToString(), TextBox1.Text)

    TextBox1.Text = str

    TextBox1.Select(TextBox1.Text.Length, 0)

    End If

    End If

    End Sub

    I hope this helps.


    Regards,

    Allen

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback