2013-12-12 51 views
-1

我有带有10个水平文本框的VB.net应用程序窗体。我需要在右键和左键盘箭头之间移动文本框。此外,我需要做的文本框格式是这样0.00VB.net通过键盘在文本框之间移动箭头

+0

你可以列出你的问题的第二部分? – webdad3

+1

不是制表符和换档标签用于什么? –

+0

你的问题的第二部分? :我需要更改文本框格式从字符串到数字像1.25,0.50,1.00 – user3077945

回答

0

除了webdad3的答案。

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 

不要忘记Form.KeyPreview设置为true(通过窗体设计器)

对于第二部分:

有很多很多不同的方式来格式化文本框的文本。 最好的解决办法是使用数据绑定(复杂的话题,读一本书了。)

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 
+0

非常感谢。 Thats Worked Ok When When .25 The Text Chang To 0.25 ...但是当我输入1时它不会更改为1.00 – user3077945

+0

您需要定义小数的精度和小数位数。 类似'Public Property Price as Decimal(10,2)' 第一个整数是精度(允许的总位数)。 第二个整数是比例(小数点后允许的位数)。 –

+0

@Jonathon - 这在.NET中无效,您无法定义小数精度。 @ user6077945 - 使用上面的代码,它应该将'1'更改为'1.00'再次检查您的代码 –

0

我从下面的链接下面的代码:

http://social.msdn.microsoft.com/Forums/windows/en-US/ffeeea42-f6ba-420f-827e-74879fd29b26/how-to- detect-arrow-keys-in-vbnet?forum=winforms

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 
相关问题