Results 1 to 23 of 23

Thread: [2008] Update textbox?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    14

    [2008] Update textbox?

    I am making a simple browser, and when I try this code it will not build.

    Code:
        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            TextBox1.Text = WebBrowser1.Location()
        End Sub

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Update textbox?

    have you tried:

    TextBox1.Text = WebBrowser1.Location.tostring ???

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Update textbox?

    i'm assuming you want to show the physical location of the webbrowser control in the textbox?

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Update textbox?

    1. Always provide as much relevant information as possible, you havent told us the error you're getting. However in this case its pretty simple to see what the problem is.
    2. You're trying to directly assign a 'Point' (the Location property returns a 'Point') to a String property. You must assign a String to a String property.
    3. You're setting the Text of TextBox1 in the TextChanged event handler, which will result in the user not being able to write anything in the textbox.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: [2008] Update textbox?

    Your trying to assign a system drawing point to a textbox, this won't work.
    What are you trying to do here ?

    btw Welcome to the forum
    If my post helps , please feel free to rate it

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    14

    Re: [2008] Update textbox?

    I am just trying to show the user where they are on the web, because now, if you type google.com and click on something, it stays google.com .

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    14

    Re: [2008] Update textbox?

    I tried:

    Code:
    TextBox1.Text = WebBrowser1.Location.tostring
    That didn't work, so I tried

    Code:
    TextBox1.Text = WebBrowser1.URL.tostring
    It showed the correct URL, but now, you cannot type in the textbox.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Update textbox?

    as Atheist said

    Quote Originally Posted by Atheist
    You're setting the Text of TextBox1 in the TextChanged event handler, which will result in the user not being able to write anything in the textbox.

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    14

    Re: [2008] Update textbox?

    So, does anyone know what I am to do?

    Quote Originally Posted by Tinbeard
    btw Welcome to the forum
    Thanks.

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Update textbox?

    can't you set textbox1.text when you change the url, instead of in the TextChanged event handler?

  11. #11

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    14

    Re: [2008] Update textbox?

    I'm not that experienced

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Update textbox?

    show us what code you've got + we might be able to help you more

  13. #13

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    14

    Re: [2008] Update textbox?

    Do you want the entire code, or just that part?

  14. #14
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Update textbox?

    the more information the better

  15. #15

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    14

    Re: [2008] Update textbox?

    Heres form1 :

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            WebBrowser1.GoBack()
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            WebBrowser1.GoBack()
        End Sub
    
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            WebBrowser1.Stop()
        End Sub
    
        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            WebBrowser1.Refresh()
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            WebBrowser1.Navigate("http://bubbabrowser.sourceforge.net")
        End Sub
    
        Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
            WebBrowser1.Navigate(TextBox1.Text)
        End Sub
    
        Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            AboutBox.ShowDialog()
        End Sub
    
        Private Sub AboutToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem1.Click
            AboutBox.Show()
        End Sub
    
        Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
            Me.Close()
        End Sub
    
        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            TextBox1.Text = WebBrowser1.Url.ToString
        End Sub
    End Class
    I think thats all you need, but heres AboutBox:

    Code:
    Imports System.Windows.Forms
    
    Public Class AboutBox
    
        Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.Close()
        End Sub
    
        Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
            Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
            Me.Close()
        End Sub
    End Class

  16. #16
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Update textbox?

    basically wherever you change the webbrowser web address you need to update the textbox.

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         WebBrowser1.GoBack()
    5.         TextBox1.Text = WebBrowser1.Url.ToString
    6.     End Sub
    7.  
    8.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    9.         WebBrowser1.GoBack()
    10.         TextBox1.Text = WebBrowser1.Url.ToString
    11.     End Sub
    12.  
    13.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    14.         WebBrowser1.Stop()
    15.         TextBox1.Text = WebBrowser1.Url.ToString
    16.     End Sub
    17.  
    18.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    19.         WebBrowser1.Refresh()
    20.         TextBox1.Text = WebBrowser1.Url.ToString
    21.     End Sub
    22.  
    23.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    24.         WebBrowser1.Navigate("http://bubbabrowser.sourceforge.net")
    25.         TextBox1.Text = WebBrowser1.Url.ToString
    26.     End Sub
    27.  
    28.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    29.         WebBrowser1.Navigate(TextBox1.Text)
    30.         TextBox1.Text = WebBrowser1.Url.ToString
    31.     End Sub
    32.  
    33.     Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    34.         AboutBox.ShowDialog()
    35.     End Sub
    36.  
    37.     Private Sub AboutToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem1.Click
    38.         AboutBox.Show()
    39.     End Sub
    40.  
    41.     Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
    42.         Me.Close()
    43.     End Sub
    44.  
    45. End Class

    but don't do it in TextBox1_TextChanged

  17. #17

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    14

    Re: [2008] Update textbox?

    You did it on lines 28-30, correct?

  18. #18
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Update textbox?

    Set it when the WebBrowsers DocumentCompleted event fires.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  19. #19
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Update textbox?

    i was just about to have a look at the webbrowser control.....

  20. #20

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    14

    Re: [2008] Update textbox?

    Okay, uhm, whatever it is doing :S . Isn't going to work x_X

  21. #21
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008] Update textbox?

    Quote Originally Posted by Atheist
    Set it when the WebBrowsers DocumentCompleted event fires.
    do what Atheist said. it should work

  22. #22
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Update textbox?

    First off, remove all occurances of this in your code:
    vb Code:
    1. TextBox1.Text = WebBrowser1.Url.ToString
    Then, in the code view, you'll see a drop-down list on the upper left corner by the code, select your WebBrowser control in it. Now the drop-down list to the right will be filled with Events for the WebBrowser control, simply select the DocumentCompleted event in it.
    An event-handler for that event will be created. Place this in it:
    vb Code:
    1. TextBox1.Text = e.Url.ToString()
    Thats all.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  23. #23

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    14

    Re: [2008] Update textbox?

    Quote Originally Posted by Atheist
    First off, remove all occurances of this in your code:
    vb Code:
    1. TextBox1.Text = WebBrowser1.Url.ToString
    Then, in the code view, you'll see a drop-down list on the upper left corner by the code, select your WebBrowser control in it. Now the drop-down list to the right will be filled with Events for the WebBrowser control, simply select the DocumentCompleted event in it.
    An event-handler for that event will be created. Place this in it:
    vb Code:
    1. TextBox1.Text = e.Url.ToString()
    Thats all.
    Awesome! Thanks so much everyone. I have another question, but I will make a new topic.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width