n00b: Making Enter do something to a text box

Author Message
tcv

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 4/15/2009
  • Status: offline
n00b: Making Enter do something to a text box Wednesday, April 22, 2009 12:06 PM (permalink)
0
I am reading a pretty good book right now. It was free from MSPress this month: Build a Program Now!:Microsoft Visual Basic 2008.

I've already run into something I want to know about! In one exercise, they have you build a web browser. It's a really simple tool that basically uses the built in WebControl. You then add a text box and a Go button, which you then tie to the text box.

Now, of course, I want to know why tapping ENTER after typing a URL doesn't bring up the web page. :-(

---

Public Class Form1

    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        MyBrowser.Navigate(txtURL.Text)
    End Sub

    Private Sub txtURL_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtURL.TextChanged

    End Sub
End Class

---

I had tried to place another "MyBrowser.Navigate(txtURL.Text)" in the txtURL_TextChanged private sub and that DID work... but only in that the browser would attempt to browser after every character. Once, I typed in, say, "CNN.com," CNN would come up whether I tapped Enter or not.

This is not all that discouraging. I am just now getting into it! :)
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    RE: n00b: Making Enter do something to a text box Thursday, April 23, 2009 2:15 AM (permalink)
    0
    Use the Keydown event. Not the TextChanged. In the event code, check the key that was pressed and if it was the enter key, then kick off the browser. It will look something like this:

    Private Sub txtURL_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs)
        if e.KeyCode = Key.Return Then
            MyBrowser.Navigate(txtURL.Text)
        End If
    End Sub


    Check that in an IDE it is from memory so probably not exactly right.
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9