Isn't there a more DotNet approach to comparing a character to see if it's a CR.?

  • Thread starter Thread starter Just Me
  • Start date Start date
J

Just Me

Below is the result of the wizard conversion from VB6.

Looking at the Help doc I can find an example that uses Chaw()

If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
e.Handled = True
End If

But isn't there a more DotNet approach to comparing a character to see if
it's a CR.?

How would you do this?

Thanks



Private Sub ComboBoxFindStr_KeyPress(ByVal ...snip

Dim lKeyAscii As Short = Asc(e.KeyChar)

'make CR work like TAB

If lKeyAscii = 13 Then

System.Windows.Forms.SendKeys.Send("{TAB}")

lKeyAscii = 0

End If

If lKeyAscii = 0 Then

e.Handled = True

End If

End Sub
 
Hows this?

Private Sub ComboBoxFindStr_KeyPress(ByVal ...snip
Dim lKeyAscii As Short = Asc(e.KeyChar)

'make CR work like TAB
If lKeyAscii.Equals(13) Then
System.Windows.Forms.SendKeys.Send("{TAB}")
lKeyAscii = 0
End If

'flag as handled is key is ASCII 0
e.Handled = lKeyAscii.Equals(0)

End Sub
 
Just Me said:
Looking at the Help doc I can find an example that uses Chaw()

If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
e.Handled = True
End If

But isn't there a more DotNet approach to comparing a character to see if
it's a CR.?

It's a more VB.NET approach:

\\\
If e.KeyChar = ControlChars.Cr Then
...
End If
///
 
JM

There are a lot, however for me is this (without the namespace) the nicest
dotNet one.

Cor
 
I do have to convert to a number and compare to 13?
I was hoping I could do something like

if e.KeyChar = somethin.CR then

I like the .Equals - I'm going to try to remember to use that.

Thanks




Noozer said:
Hows this?
IS THIS OK - ANY REASON TO SET Handled TO false?
Private Sub ComboBoxFindStr_KeyPress(ByVal ...snip
Dim lKeyAscii As Short = Asc(e.KeyChar)

'make CR work like TAB
If lKeyAscii.Equals(13) Then
System.Windows.Forms.SendKeys.Send("{TAB}")
'''lKeyAscii = 0

e.Handled = true
 
Just Me,
As Herfried suggests, I would use ControlChars.CR:
If e.KeyChar = ControlChars.CR Then

System.Windows.Forms.SendKeys.Send("{TAB}")
Rather then use SendKeys.Send to tab to the next control, you should be able
to use Control.SelectNextControl to tab to the next control.

Me.SelectNextControl(ComboBoxFindStr, True, True, True, True)

If you are using the same handler for multiple controls, you could use
something like:

Me.SelectNextControl(DirectCast(sender, Control), True, True,
True, True)

Hope this helps
Jay
 
Jay B. Harlow said:
Just Me,
As Herfried suggests, I would use ControlChars.CR:

Rather then use SendKeys.Send to tab to the next control, you should be
able to use Control.SelectNextControl to tab to the next control.

Me.SelectNextControl(ComboBoxFindStr, True, True, True, True)

If you are using the same handler for multiple controls, you could use
something like:

Me.SelectNextControl(DirectCast(sender, Control), True, True,
True, True)

Hope this helps
Jay

Thanks, I'll look check this out.
 
Back
Top