? Trouble with calling a sub vs onClick Event ?

vmars316 621 Reputation points
2020-09-01T23:35:07.683+00:00

Hello & Thanks ;

Normally I call this Sub
Private Sub Target_self_Click(sender As Object, e As EventArgs) Handles Target_self.Click
Via a Button click .
But now I want get rid of the Button , and call a Sub with the same code via this
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Private Sub ChangeBlankToSelf()

I get no error msg , just this:
1>------ Build started: Project: GetElementByTag, Configuration: Debug Any CPU ------
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I will try to Post the code via a Quote , since when I try to enter code as code , I get ACCESS DENIED .
Thanks for your Help...

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    Dim PageElements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")
    txbAddress.Text = WebBrowser1.Url.ToString
    ChangeBlankToSelf()
End Sub

Private Sub Target_self_Click(sender As Object, e As EventArgs) Handles Target_self.Click
    Dim TimesThruCount = 0
    Dim linkElements As HtmlElementCollection =
       WebBrowser1.Document.GetElementsByTagName("A")
    Dim firstLink = linkElements.Cast(Of HtmlElement).FirstOrDefault()
    For Each link As HtmlElement In linkElements
        If link.GetAttribute("target") = "_blank" Then
            '                firstLink.SetAttribute("target", "_self")
            link.SetAttribute("target", "_self")
            EachSetLine.Text = EachSetLine.Text & ControlChars.NewLine & link.OuterHtml
        End If
        TimesThruCount = TimesThruCount + 1
    Next
End Sub

Private Sub ChangeBlankToSelf()
    Dim TimesThruCount = 0
    Dim linkElements As HtmlElementCollection =
       WebBrowser1.Document.GetElementsByTagName("A")
    Dim firstLink = linkElements.Cast(Of HtmlElement).FirstOrDefault()
    For Each link As HtmlElement In linkElements
        If link.GetAttribute("target") = "_blank" Then
            '                firstLink.SetAttribute("target", "_self")
            link.SetAttribute("target", "_self")
            EachSetLine.Text = EachSetLine.Text & ControlChars.NewLine & link.OuterHtml
        End If
        TimesThruCount = TimesThruCount + 1
    Next
End Sub
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,860 questions
{count} votes

0 additional answers

Sort by: Most helpful