?Form Control Navigation

kcnielsen

New member
Joined
Aug 26, 2005
Messages
3
Programming Experience
5-10
I am attempting to implement enter key navigation on some forms in vb.net using the keypreview on and setting a sub to handle mybase.keyup.

I am trapping the enter key to move from the active control to the next control. It works fine but the app beeps upon hitting the enter key. Any ideas on how to suppress or prevent the beep?
 
That didn't work because I am running through several control types, but it did point me into the right direction.

I created a boolean CheckKey function and pass in the event keypress args, check for keychar 13 there and return true or false.

In the indvidual control keypress "e.Handled = CheckKey(e.[keypressargs])"

Works perfically for all control types I am looping through.

Thanks!
 
in the textbox's keyup event is where you should put the code to move to the next control (of course you would have to do this with every control)

here's a code sample from one of my programs:

the program keeps track of computer parts prices and inventory, in this example whenever the user presses enter it'll move to the next part and whenever the user presses escape it moves back to the previous part

13 = enter key
27 = escape key
VB.NET:
	Private Sub AllKeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtCPU.KeyUp, txtHeatSink.KeyUp, txtMobo.KeyUp, txtRam.KeyUp, txtVideo.KeyUp, txtSound.KeyUp, txtHDD1.KeyUp, txtBurner.KeyUp, txtCPUqty.KeyUp, txtHeatSinkqty.KeyUp, txtMoboqty.KeyUp, txtRamqty.KeyUp, txtVideoqty.KeyUp, txtSoundqty.KeyUp, txtHDD1qty.KeyUp, txtBurnerqty.KeyUp
		Dim TextBox As TextBox = CType(sender, TextBox)
		Select Case TextBox.Name
			Case "txtCPU"
			    If e.KeyValue = 13 Then txtHeatSink.Focus()
			    If e.KeyValue = 27 Then txtCustName.Focus()
			Case "txtHeatSink"
			    If e.KeyValue = 13 Then txtMobo.Focus()
			    If e.KeyValue = 27 Then txtCPU.Focus()
			Case "txtMobo"
			    If e.KeyValue = 13 Then txtRam.Focus()
			    If e.KeyValue = 27 Then txtHeatSink.Focus()
			Case "txtRam"
			    If e.KeyValue = 13 Then txtVideo.Focus()
			    If e.KeyValue = 27 Then txtMobo.Focus()
			Case "txtVideo"
			    If e.KeyValue = 13 Then txtSound.Focus()
			    If e.KeyValue = 27 Then txtRam.Focus()
			Case "txtSound"
			    If e.KeyValue = 13 Then txtHDD1.Focus()
			    If e.KeyValue = 27 Then txtVideo.Focus()
			Case "txtHDD1"
			    If e.KeyValue = 13 Then txtBurner.Focus()
			    If e.KeyValue = 27 Then txtSound.Focus()
			Case "txtBurner"
			    If e.KeyValue = 13 Then txtCustName.Focus()
			    If e.KeyValue = 27 Then txtHDD1.Focus()
		 End Select
	End Sub
 
Back
Top