Webbrowser Navigate Via a Text Line Double-Clicked In a Richtextbox.....

คำตอบ Webbrowser Navigate Via a Text Line Double-Clicked In a Richtextbox.....

  • 14 เมษายน 2555 3:10
     
      มีโค้ด

    I would like for my program to open up a new form (It will be in Form4 webbrowser) and the form will navigate via the text line that was double-clicked in a RichTextBox1. Here is an illustration showing what I'm trying to accomplish:

    Here is the code that I have so far:

    Private Sub RichTextBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseDoubleClick
            Form4.Show()
            Form4.WebBrowser1.Navigate("http://www.google.com/search?q=" & "THIS IS THE AREA OF CODE THAT I NEED TO MAKE THE RICHTEXTBOX1 CLICKABLE!!!" )
        End Sub

    I would appreciate any help...


    • แก้ไขโดย TeachMe 14 เมษายน 2555 3:14
    •  

ตอบทั้งหมด

  • 14 เมษายน 2555 3:27
     
      มีโค้ด

    I think using a Listbox would be a better choice than a RTB.

    Private Sub Listbox1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.MouseDoubleClick
            Form4.Show()
            Form4.WebBrowser1.Navigate("http://www.google.com/search?q=" & ListBox1.SelectedItem.ToString)
        End Sub


    Sorry if my English is poor, it's not my first language. :) Programming FTW! Samuel
    Useful links:


  • 14 เมษายน 2555 4:10
     
      มีโค้ด

    I think using a Listbox would be a better choice than a RTB.

    Private Sub Listbox1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.MouseDoubleClick
            Form4.Show()
            Form4.WebBrowser1.Navigate("http://www.google.com/search?q=" & ListBox1.SelectedItem.ToString)
        End Sub


    Sorry if my English is poor, it's not my first language. :) Programming FTW! Samuel
    Useful links:


    I prefer to use a Richtextbox for a few reasons:

    1- I already have a bunch of other code & functions using the Richtextbox

    2- It's difficult to save the data that was inside of a listbox when you close down the form.

    I prefer to use a richtextbox but if I use the listbox, how do I count the lines inside of the Listbox? I already have the right code for the richtextbox...

  • 14 เมษายน 2555 4:42
     
      มีโค้ด

    I think using a Listbox would be a better choice than a RTB.

    Private Sub Listbox1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.MouseDoubleClick
            Form4.Show()
            Form4.WebBrowser1.Navigate("http://www.google.com/search?q=" & ListBox1.SelectedItem.ToString)
        End Sub


    Sorry if my English is poor, it's not my first language. :) Programming FTW! Samuel
    Useful links:


    This code doesn't work for the listbox either...
  • 14 เมษายน 2555 5:56
     
     

    For your question, it is about web page automation or web scraping. For more info about this, please see the VB.Net FAQ about this topic at:

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/5f2a5f51-169b-4b56-89d6-01b1d314fdf0

    They are located in the WebBrowser section.

    Hope it helps.


    My blog: http://soho-hsh.blogspot.com

  • 14 เมษายน 2555 16:17
     
     

    For your question, it is about web page automation or web scraping. For more info about this, please see the VB.Net FAQ about this topic at:

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/5f2a5f51-169b-4b56-89d6-01b1d314fdf0

    They are located in the WebBrowser section.

    Hope it helps.


    My blog: http://soho-hsh.blogspot.com

    Navigating with a webbrowser is not web scraping or considered web automation such as automating forms. My question wasn't about that. But anyways, I figured it out myself so thanks for nothing to all the people that I know for a fact could have easily answered this here at the msdn. You guys are getting worse and worse with your support here...
    • แก้ไขโดย TeachMe 14 เมษายน 2555 16:18
    •  
  • 14 เมษายน 2555 17:01
     
      มีโค้ด

    I prefer to use a Richtextbox for a few reasons:

    1- I already have a bunch of other code & functions using the Richtextbox

    2- It's difficult to save the data that was inside of a listbox when you close down the form.

    I prefer to use a richtextbox but if I use the listbox, how do I count the lines inside of the Listbox? I already have the right code for the richtextbox...

    On question 2 here, you can do something like this:

        Private Sub Form1_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
            System.IO.File.WriteAllLines("C:\Folder\File.txt", ListBox1.Items)
        End Sub

    And when the form starts up, you can check whether or not the file exists. If it does, replace current ListBox content with the saved data.

        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            If System.IO.File.Exists("C:\Folder\File.txt") Then
                ListBox1.Items.Clear()
                ListBox1.Items.AddRange(System.IO.File.ReadAllLines("C:\Folder\File.txt"))
            End If
        End Sub

    On your question 3, counting the elements will be as simple as ListBox1.Items.Count.

    Also, remember:

                ' Add item to ListBox:
                ListBox1.Items.Add("Item")
                ' Add range of items to ListBox:
                ListBox1.Items.AddRange({"Item 1", "Item 2"})
                ' Remove item from ListBox:
                ListBox1.Items.Remove("Item") '<-- Using name of item
                ListBox1.Items.RemoveAt(1) '   <-- Using index of item
                ' Remove all items from ListBox:
                ListBox1.Items.Clear()

    Hope this helps!

    Sincerely yours,
    - bilde2910


    If a post is helpful to you or solves a problem, remember to mark it as answer, propose it as answer or vote up.
    Check out my development so far!

  • 14 เมษายน 2555 18:04
     
     คำตอบ มีโค้ด

    After a little googling and a lot of struggling, suddenly I came across a working method that is suprisingly simple:

        Private Sub RichTextBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseDoubleClick
            Dim LineCurosorIsIn As Integer = RichTextBox1.GetLineFromCharIndex(RichTextBox1.GetFirstCharIndexOfCurrentLine)
            Dim StringSelected As String = RichTextBox1.Lines(LineCurosorIsIn)
            Form4.Show()
            Form4.WebBrowser1.Navigate("http://www.google.com/search?q=" & StringSelected)
        End Sub

    Hope this helps more than the one above ;) 

    - bilde2910

    EDIT: There is a little bug with this, if the last line is left blank, and it is double-clicked, Windows will automatically select the character before (the linebreak), which is infact on the previous line. Say that the box has 5 lines, of which the 5th line doesn't have anything written on it. If the user double-clicks that last blank line, Windows will select the line break (whose index is on the 4th line). This will shift the selection start position one character back, so it suddenly is on line 4 instead of 5. Therefore, avoid having a blank line as the last line.


    If a post is helpful to you or solves a problem, remember to mark it as answer, propose it as answer or vote up.
    Check out my development so far!


    • แก้ไขโดย bilde2910 14 เมษายน 2555 18:09
    • ทำเครื่องหมายเป็นคำตอบโดย Shanks ZenMicrosoft, Moderator 25 เมษายน 2555 9:34
    •