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.
Related
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
This I thought would be easy. I have not used VB.NET all that much, and I am trying to open up a form from a button click. The form will not show and I get a null exception error.
What is wrong with the code?
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
Dim A
A = AboutBox1
A.Show()
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) _
Handles Button3.Click
Dim box = New AboutBox1()
box.Show()
End Sub
You can also use showdialog
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) _
Handles Button3.Click
dim mydialogbox as new aboutbox1
aboutbox1.showdialog()
End Sub
You could use:
Dim MyForm As New Form1
MyForm.Show()
or rather:
MyForm.ShowDialog()
to open the form as a dialog box to ensure that user interacts with the new form or closes it.
You may like to first create a dialogue by right clicking the project in solution explorer and in the code file type
dialogue1.show()
that's all !!!
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
I am trying to launch a separate instance of my application with a new process ID. Is there any way to do this? The following code will show a separate form, but it shares the process ID of the original form:
Private Sub NewToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles NewToolStripMenuItem.Click
Dim SecondForm As New MyForm()
SecondForm.Show()
End Sub
I basically want to replicate the same behavior as opening the application when a user selects the New option from the tool strip menu.
I found a solution for what I was trying to do.
Private Sub NewToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles NewToolStripMenuItem.Click
Dim ExePath As String = Application.ExecutablePath
Process.Start(ExePath)
End Sub
I'd like to be able to drag a file/executable/shortcut into a Windows Forms application and have the application determine the original path of the dropped file then return it as a string.
E.g. drag an image from the desktop into the application and messagebox up the local path of the image.
Is that possible? Could someone provide me with an example maybe?
It's quite easy. Just enable drap-and-drop by setting the AllowDrop property to True and handle the DragEnter and DragDrop events.
In the DragEnter event handler, you can check if the data is of the type you want using the DataFormats class.
In the DragDrop event handler, use the Data property of the DragEventArgs to receive the actual data and the GetData method
Example:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.AllowDrop = True
End Sub
Private Sub Form1_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
For Each path In files
MsgBox(path)
Next
End Sub
Private Sub Form1_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
This is just a note to state that if drag and drop does not work, it could be because you are running Visual Studio in Administrator Mode (Windows 7 and up I believe).
This also has to do with the UAC level currently set on your Windows installation.