Catching carrage return

I am trying to catch the carrage return with this code I found on net but doesn't seem to work. Nothing happens.
Is there another way to do it?



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

Wayne

[642 byte] By [WayneSpangler] at [2008-2-15]
# 1
You could try


If e.KeyChar = (vbcrlf) Then

Blisardo at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2


If e.KeyChar = ControlChars.Cr Then

JoeSmugeresky at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
Sorry guys neither one worked. I am using vbexpress beta 2 do you think it might be a bug in it?

WayneSpangler at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
Which event are you using this from?
JoeSmugeresky at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5

A combo box



Private Sub cbbURL_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cbbURL.KeyPress

WayneSpangler at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6
I just added a break point in the cbbURL_KeyPress and the return does not call this routine. Do you think I should post a bug report or do you think others have reported it?
WayneSpangler at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 7

Its not a bug, you need to create a derived control and override the Control.IsInputKey method.


protected override bool IsInputKey(Keys keyData)
{
if ((keyData & Keys.KeyCode) == Keys.Enter)
{
return true;
}

return base.IsInputKey(keyData);
}


Protected Overrides Function IsInputKey(ByVal keyData As Keys) As Boolean

If ((keyData And Keys.KeyCode) = Keys.Enter) Then
Return True
End If

Return MyBase.IsInputKey(keyData)

End Function

Once you have done that the KeyPress event should be raised on ENTER.

DavidM.Kean at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 8
Thanks David,
I am new to vb net so I don't know anything about derived controls and overiding but am about to find out.
Thanks again,
WayneSpangler at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 9
what calls the protected overrides function? i have included a break in this function, but it is never called...
msbair at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 10


Wayne

At times you have to check for Chr (10 ) too .

Shasur

Shasur at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic General...