Vb.net WebBrowser NewWindow2 how to do? - vb.net

i find some information. Microsoft Web Browser can get NewWindow2 like this,
Private Sub AxWebBrowser1_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles AxWebBrowser1.NewWindow2
Dim frmWB As Form1
frmWB = New Form1()
frmWB.AxWebBrowser1.RegisterAsBrowser = True
e.ppDisp = frmWB.AxWebBrowser1.Application
frmWB.Visible = True
End Sub
But i need for WebBrowser. Not Microsoft Web Browser.
Anyone knows?

To do this on a normal webbrowser control would be like
Private Sub WebBrowser1_NewWindow(sender as Object, e as CancelEventArgs) _
Handles WebBrowser1.NewWindow
'code
End Sub
If you needed or wanted to you can also import the Microsoft web browser control and just use it

Related

How can I interact with parallel page loaded from WebView2?

I have written some VB.Net code using WebView2 control to try to download a PDF file from a specific magazine.
My VB.Net code is following
Imports Microsoft.Web.WebView2.Core
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Call InitializeAsync()
End Sub
Async Sub InitializeAsync()
Await wv.EnsureCoreWebView2Async()
wv.CoreWebView2.Navigate("https://journal.cinetelerevue.sudinfo.be")
End Sub
Private Sub wv_NavigationCompleted(sender As Object, e As CoreWebView2NavigationCompletedEventArgs) Handles wv.NavigationCompleted
Threading.Thread.Sleep(1000)
Call ClickOnPdfButton()
Threading.Thread.Sleep(1000)
End Sub
Async Sub ClickOnPdfButton()
Dim sButtonCmd = "document.getElementById('readPdfBtn').click();"
Dim task = Await wv.ExecuteScriptAsync(sButtonCmd)
End Sub
End Class
The first Navigate() method display correctly requested URL.
The Javascript document.getElementById('readPdfBtn').click(); method works also correclty. It open a NEW window because Javascript code linked to click() method do following action
var e = window.open("","pdf_view");
When program has run, I obtain following result
I have painted a red circle around PDF button in first Window.
My problem is that I need to continue to click on another PDF button contained in new Window to initiate PDF download.
How can I access it using wv WebView2 variable ?
In tasks manager, I can see that new Windows is attached to Extract-PDF-From-Web application that is the name of my VB.Net application.
To solve this issue, I have added an event handler in wv.NavigationCompleted event in which I have changed e.NewWindow property.
I have also try to set URI but without success.
The full VB.Net solution that works using Visual Studio 2022 is following
Imports Microsoft.Web.WebView2.Core
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Call InitializeAsync()
End Sub
Async Sub InitializeAsync()
Await wv.EnsureCoreWebView2Async()
wv.CoreWebView2.Navigate("https://journal.cinetelerevue.sudinfo.be")
End Sub
Public Sub NewWindowRequested(sender As Object, e As CoreWebView2NewWindowRequestedEventArgs)
e.Handled = True
Dim cwv As CoreWebView2 = sender
e.NewWindow = cwv
End Sub
Private Sub wv_NavigationCompleted(sender As Object, e As CoreWebView2NavigationCompletedEventArgs) Handles wv.NavigationCompleted
AddHandler wv.CoreWebView2.NewWindowRequested, AddressOf Me.NewWindowRequested
Threading.Thread.Sleep(1000)
Call ClickOnPdfButton()
End Sub
Async Sub ClickOnPdfButton()
Dim sButtonCmd = "document.getElementById('readPdfBtn').click();"
Dim task = Await wv.ExecuteScriptAsync(sButtonCmd)
End Sub
End Class
After running this code, I obtain following result

How to send an image through the Skype API?

I am using the Skype4ComLib library to try and send an image to a contact on Skype.
Private Sub Button17_Click(sender As Object, e As EventArgs) Handles btnImageLoad.Click
OpenFileDialog1.ShowDialog()
PicBox.ImageLocation = OpenFileDialog1.FileName.ToString
End Sub
This opens a dialog box for the user to select an image and loads it into a picture box called PicBox.
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
TimerImage.Stop()
End Sub
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button16.Click
TimerImage.Stop()
End Sub
Buttons 15 and 16 start the timer.
I want to send the image from within the timer but I can't use skype.sendmessage as it only accepts a string.
Any ideas?
Using the SendKeys.Send method you can paste the picture from the clipboard in the message via the actual Skype application.
This is how I do it:
My.Computer.Clipboard.SetImage(PicBox.Image)
SkypeClient.Client.OpenMessageDialog("<contact to send to>")
SkypeClient.Client.Focus()
SendKeys.Send("^(V){ENTER}")
Replace <contact to send to> with the name of the contact you want to send the picture to.

Web popup window from VB?

I want to generate a web popup window when a user clicks a linklabel in my VB application.
Ideally the popup window will be using whatever the users default browser is.
Is this possible?
Any ideas how?
Thanks :)
Process.Start(Url)
should do what you want.
use Process.Start("http://www.google.com") on click event
Use Process.Start in the LinkClicked event of the LinkLabel
Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Process.Start("http://www.bbc.co.uk")
End Sub
If you want to specify the URL at some point earlier you could store this in the Tag field:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LinkLabel1.Tag = "http://www.bbc.co.uk"
End Sub
Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Process.Start(LinkLabel1.Tag.ToString)
End Sub

Pulling information from the Page Source

Ok so I have been have alot of trouble with the
Web browser control on a few applications I am working on.
All of them share the same issue. I want to have the application navigate s webpage a read the write the text in the page source to a variable. I also need to be able to save the files afterwards.
Some Source code:
Public Class Form4
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
MyFolderBrowser.Description = "Select the Folder"
MyFolderBrowser.ShowNewFolderButton = False
Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()
If dlgResult = Windows.Forms.DialogResult.OK Then
TextBox1.Text = MyFolderBrowser.SelectedPath
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = "" Then
MessageBox.Show("You have to select a directory!")
Else
WebBrowser1.Navigate("www.realmofthemadgod.com/version.txt")
System.Threading.Thread.Sleep(3000)
Dim PageSource As String = WebBrowser1.Document.Body.InnerText
WebBrowser1.Navigate("http://www.realmofthemadgod.com/AssembleeGameClient" & PageSource & ".swf")
End If
End Sub
End Class
The first thing I am having an issue with is that it never waits for the webpage to load before pulling the Document text. I have tried many different ways to from different solutions people have posted to get around this. Oddly it always seems to work if I do it a second time.
And I want to save the final resulting webpage as an swf to the selected directory if Button2 is clicked.
Thanks for any help I have been looking for this everywhere
Welcome to the dark art of web scraping. First off, I would recommend using WebClient instead of WebBrowser as it has discrete methods for downloading data from web sites. It looks like your version.txt only contains the data you want (and no extraneous html) so we can download it directly. If you needed to parse html I would use HtmlAgilityPack. Untested code to get you started:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = "" Then
MessageBox.Show("You have to select a directory!")
Else
Using wc as New WebClient()
Dim version = wc.DownloadString("www.realmofthemadgod.com/version.txt")
Dim swf = "http://www.realmofthemadgod.com/AssembleeGameClient" + version + ".swf"
wc.DownloadFile(swf,"c:\temp\myswf.swf")
End Using
End If
End Sub

Accessing Internet Explorer using vb.net

I'm trying to create a little executable that when launched opens an IE browser to various websites like news sites all in different tabs. for example, a tab for wsj, nytimes, etc. How do I access IE with vb.net? What reference do I need to add? I can't find any sample code that I can make work I think it is because I am missing a library in my assembly?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenURL("www.google.com")
End Sub
Private Sub OpenURL(ByVal URL As String)
System.Diagnostics.Process.Start(URL)
End Sub
'Or
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim TheBrowser As Object = CreateObject("InternetExplorer.Application")
TheBrowser.Visible = True
TheBrowser.Navigate("www.google.com")
End Sub
'Or add Reference SHDocVw.dll By Browsing System32
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim TheBrowser = New SHDocVw.InternetExplorerMedium
TheBrowser.Visible = True
TheBrowser.Navigate(URL:="http://www.google.com")
End Sub
You can't open them in tabs:
Programmatically open a new tab in ie7
Is your application a console application? You can't create multiple tabs, but you can use a System.Diagnostics.Process to launch individual instances of Internet Explorer. You should be able to simply specify the full address of the website as the Process to run, similar to how you can put "http://www.wsj.com" into a run prompt, which will launch your default browser with the Wall Street Journal's website.
If you are using WinForms, you could always use a WebBrowser control, but that has limitations for tabs as well.