I Have VB.net application form with 10 horizontal text boxes . I need to move between text boxes with right And Left Keyboard Arrow . Also I need Make textBoxes Format To Be Like This 0.00
Asked
Active
Viewed 2,277 times
-1
-
Can you restate the 2nd part of your question? – webdad3 Dec 12 '13 at 14:13
-
1Isn't what tab and shift-tab use for? – the_lotus Dec 12 '13 at 14:29
-
2nd part of your question? : I Need To Change Textboxes Format From String To number Like 1.25 , 0.50 , 1.00 – user3077945 Dec 12 '13 at 14:34
-
For the second part; you could either databind the textbox to an object with a decimal property with scale set to 2 or you could just have some logic in each textbox's TextChanged event; `IF Textbox1.Text = IsNumeric(False) Then` etc – Jonathon Cowley-Thom Dec 12 '13 at 14:39
2 Answers
0
I got the following code from the following link:
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
' Sets Handled to true to prevent other controls from
' receiving the key if an arrow key was pressed
Dim bHandled As Boolean = False
Select Case e.KeyCode
Case Keys.Right
'do stuff
e.Handled = True
Case Keys.Left
'do other stuff
e.Handled = True
Case Keys.Up
'do more stuff
e.Handled = True
Case Keys.Down
'do more stuff
e.Handled = True
End Select
End Sub

webdad3
- 8,893
- 30
- 121
- 223
0
In addition to webdad3's answer.
Private Sub Form1_KeyDown(ByVal sender as Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Dim tb as TextBox = TryCast(me.ActiveControl, TextBox)
If tb IsNot Nothing Then
Select Vase e.KeyCode
Vase Keys.Right, Keys.Left
dim forward as boolean = e.KeyCode = Keys.Right
me.SelectNextControl(Me, forward, True, True, true)
e.Handled = true
End Select
End If
End Sub
Don't forget to set Form.KeyPreview to true (via Forms Designer)
For the second part:
There are many, many different ways to format the text of a textbox. The best solution would be to use DataBindings (complex topic, read a book about it.)
Public Class Form1
Public Property Price as Decimal
' call this code once
Private Sub InitControls()
Price = 3.45
me.txtPrice.DataBindings.Add(
"Text", Me, "Price", True,
DataSourceUpdateMode.OnPropertyChanged, Nothing, "0.00"
)
End Sub
End Class

Jürgen Steinblock
- 30,746
- 24
- 119
- 189
-
thank you so much . Thats Worked Ok When Type .25 The Text Chang To 0.25 ... But When I Type 1 It Is Not Changed To 1.00 – user3077945 Dec 12 '13 at 15:10
-
You need to define the precision and scale of the decimal. Something like `Public Property Price as Decimal(10,2)` The first integer is the precision (the total number of digits allowed). The second integer is the scale (the number of digits allowed after the decimal point). – Jonathon Cowley-Thom Dec 12 '13 at 16:09
-
@Jonathon - This is not valid in .NET, you can't define a decimal precision. @user6077945 - with the above code it should change `1` to `1.00` double check your code – Jürgen Steinblock Dec 13 '13 at 06:42