VB.Net Open New Form Instance as Separate Process - vb.net

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

Related

Open another form when clicking an item in ListBox VB.net

I'm a network admin that have been task to do a paperless meeting system. So right now I'm looking at VB.net as my platform. My goal is populate a listbox with items inside a folder using their filenames, it's mostly PDF files. So i have achieve that goal and when I click the items in the listbox it the file in the folder opens. What I want is, if I click an item in the listbox, another form will show. This form has an embedded pdf reader and a textbox for comments. textbox will be save in a .txt file inside a another folder. here's my code
Public Class Form2
Dim MyFolderPath As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "C:\Users\ICTCAdmin\Desktop\Board Meeting\Academic")
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
For Each fullpath As String In IO.Directory.GetFiles(MyFolderPath)
ListBox1.Items.Add(IO.Path.GetFileName(fullpath))
Next
Catch ex As Exception
MsgBox(ErrorToString)
End Try
End Sub
Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Form1.Show()
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim fullpath As String = IO.Path.Combine(MyFolderPath, ListBox1.SelectedItem.ToString)
Process.Start(fullpath)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
End Class
Thank you in advance.
In your second form create a Friend property like this at the top of the child form's code window
Public Class frmWhateverYourNewFormIsCalled
Friend Property filepath As String
In your calling form edit the listbox1_SelectedIndexChanged property to this
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim fullpath As String = IO.Path.Combine(MyFolderPath, ListBox1.SelectedItem.ToString)
dim childForm as new frmWhateverYourNextFormIsCalled
childForm.filepath = ""
childForm.Show()
End Sub
In your child form add in code to open the filePath in your embedded pdf reader. Probably in the Shown event handler. Not the Load event handler.
To view pdfs within your program this might help
Displaying a PDF in a control in Visual Basic 2010

How to open up a form from another form in VB.NET?

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 !!!

Trying to enter a name in a textbox, hit ok, and have that form close and pass the info to another forms label

***THE CODE FROM THE FIRST WINDOW GOES INTO A TEXT BOX AND YOU HIT THE BUTTON HERE.
Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
Me.Close()
End Sub
***THE CODE ON THE FORM WHERE I WANT THE INFO TO BE PLACED IS HERE.
Private Sub Loan1Form_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.lblCompanyName.Text = DataEntryForm.txtCompanyNameInput.Text
End Sub
Anyway's that's what I found on a youtube video and im having trouble getting it to work. Any help would be appreciated.
Thanks.
Pass the data to an instance of the form:
Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
Dim f As New OtherForm
f.lblCompanyName.Text = txtCompanyNameInput.Text
f.Show()
Me.Close() 'make sure this form is not the one that closes the app if it closes
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.