Why does Microsoft do this or am I missing something:Keypress event missing in VB.NET 2008
-
Hi all Though its great to have new features with every release, it sucks if Microsoft takes away old stuff that worked actually great. I have a searchtextbox with a search button. And what I want to build in is if someone enter something in the textbox and press enter it should hit the underlying code. For this I need to use the textbox Keypress Event. If you look at the code below, I get an error: Event 'KeyPress' cannot be found I have to use VB, its the company's policy.No Javascript Private Sub SearchTxt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles SearchTxt.KeyPress If Asc(e.KeyChar) = Windows.Forms.Keys.Enter Then GoButton.PerformClick() End If End Sub Thank you for your time
-
Hi all Though its great to have new features with every release, it sucks if Microsoft takes away old stuff that worked actually great. I have a searchtextbox with a search button. And what I want to build in is if someone enter something in the textbox and press enter it should hit the underlying code. For this I need to use the textbox Keypress Event. If you look at the code below, I get an error: Event 'KeyPress' cannot be found I have to use VB, its the company's policy.No Javascript Private Sub SearchTxt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles SearchTxt.KeyPress If Asc(e.KeyChar) = Windows.Forms.Keys.Enter Then GoButton.PerformClick() End If End Sub Thank you for your time
Can't test it in 2008 at the moment but you can just use the 'keydown' event.
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
gobutton.performclick()
End If
End Sub -
Hi all Though its great to have new features with every release, it sucks if Microsoft takes away old stuff that worked actually great. I have a searchtextbox with a search button. And what I want to build in is if someone enter something in the textbox and press enter it should hit the underlying code. For this I need to use the textbox Keypress Event. If you look at the code below, I get an error: Event 'KeyPress' cannot be found I have to use VB, its the company's policy.No Javascript Private Sub SearchTxt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles SearchTxt.KeyPress If Asc(e.KeyChar) = Windows.Forms.Keys.Enter Then GoButton.PerformClick() End If End Sub Thank you for your time
Perhaps you should try to reinstall visual studio, because the KeyPress event has not been removed from vb.net / vs 2008 (I use it in several apps myself). Or is your "searchtextbox" not a regular textbox?
My advice is free, and you may get what you paid for.
-
Hi all Though its great to have new features with every release, it sucks if Microsoft takes away old stuff that worked actually great. I have a searchtextbox with a search button. And what I want to build in is if someone enter something in the textbox and press enter it should hit the underlying code. For this I need to use the textbox Keypress Event. If you look at the code below, I get an error: Event 'KeyPress' cannot be found I have to use VB, its the company's policy.No Javascript Private Sub SearchTxt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles SearchTxt.KeyPress If Asc(e.KeyChar) = Windows.Forms.Keys.Enter Then GoButton.PerformClick() End If End Sub Thank you for your time
Member 4420534 wrote:
I have to use VB, its the company's policy.No Javascript
This is either an idiotic statement, or you're writing a website, in which case you should have asked in the ASP.NET forum, and in which case, it's always been the case that you can't handle a keypress event, or a keydown, or anything like that. It would, of course, be utterly retarded for a page to do postbacks every time you press a key.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.