VB.NET MessageBox Help link opens several times - vb.net

Message
I need to add a help button in my message box then find the answer here Clickable URL in a Winform Message Box? which is great! however, when I use this code inside a button then click the help button, it opens 2 tabs with the same link.
Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
MessageBox.Show(
"test message",
"caption",
MessageBoxButtons.YesNo,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1,
0, '0 is default otherwise use MessageBoxOptions Enum
"http://google.com",
"keyword")
End Sub
-Update: I just tried it with the new project Winforms .NET 5.0 and it's working fine, but I need this on my current project.

Related

vb .net check if the only open window is current window

i'm working on a project that has several windows that the user opens AFTER clicking on a "start" button. i need to restrict the user by showing an error message if the "start" button is clicked WHEN other windows are still open.
here's what i got for the main window with the "start" button:
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
Dim openForms As New FormCollection()
openForms = Application.OpenForms()
If openForms.Count > 1 Then
MessageBox.Show("ERROR MESSAGE", "Errors", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
'some codes here
End If
End Sub
the problem with the above code, is that not all windows are "disposed" properly, hence it remains in an "open" state even after they are closed. and i am not in the position to edit those other windows. any help would be appreciated.
You can try it like this:
If Application.OpenForms().OfType(Of Form2).Any Then
MessageBox.Show("Opened")
Else
'Else
End If

Application Auto-closes after dialog box

New to VB.NET but pretty stumpped at the moment.
My Windows Form application launches 'Form1' which then starts a dialog box using:
Dim dialogResult As Boolean = configWizard.ShowDialog()
The ConfigWizard then writes some data to the registry, pops up with the new registry values and closes at which point the rest for Form1 loads.
This all works fine.. When debugging from Visual Studio 2015.
The problem I'm facing is when I build an installer for this program using the in-built InstallShield. The installer set the registry values on install (which works perfectly) then the dialog box opens, sets new values and pops up with the new values it's written. This all works fine. However, the Form1 closes straight away as soon as I press 'OK' on the dialog box.
It's supposed to pop up with a message box saying 'True' but the entire program closes.
Upon constant running of the program it did appear that the Form1 did flash up for milliseconds before disappearing. Does seem like the program is just closing for some unknown reason. I'm pretty stumped as to how to stop the Form1 from closing. Any light of questions to help out would be must appreciated.
I've omitted some code that is irrelivent.
I managed to quick take a screenshot when the Form1 did flash up (verifying both Form1 and the messagebox saying 'True' ARE loading after the dialogbox is closing.. albeit only for a split second)
Code:
Dialog Box:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
myValue1= Me.myValue1.Text
myValue2= Me.myValue2.Text
Dim regKey As RegistryKey
regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\removedSoftware", True)
regKey.SetValue("value1", myValue1)
regKey.SetValue("value2", myValue2)
MsgBox(myValue1 & " + " & myValue2)
MsgBox("Registry: " & regKey.GetValue("value1") & " data: " & regKey.GetValue("value2"))
regKey.Close()
Me.Close()
End Sub
Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dialogResult As Boolean = configWizard.ShowDialog()
Try
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
MsgBox(dialogResult)
End Sub
Use OnShown event (Form1_Shown) instead of OnLoad to display the dialog box.

How to open a new form but closing the old one in VB

I have a welcome to my application as it loads up, but then need to have that form close and login form open when the continue button is hit.
My code:
Me.Close()
Dim Login As New Form
Login.Show()
When I click the button it only closes the welcome form and then ends the application. If you can help thanks! :)
You can set the properties of the project to select "When last form closes" in the shutdown mode dropdown
Update:-
"Project" menu -> 'YourApp' Properties... -> Application Tab
find : "Shutdown Mode"
Change from
"When startup form closes" --> "When last form closes"
show the form before the close.
Dim Login As New Form
Login.Show()
Me.Close()
Better is if you use Me.Hide()
There is a shutdown mode project property. This controls the application lifecycle.
Make sure you set this to "When last form closes"
Then your code should work as you expect.
What is happening is that you have that setting set to shutdown "when startup form closes", so by doing Me.Close on the startup form, this shuts down the application, all code after this line is effectively ignored.
If your Welcome Form isn't your main form, you just need to put your Me.Close after your Login.Show()
Dim Login As New Form
Login.Show()
Me.Close()
Try this..
On your welcome form when closing:
Me.hide()
Dim Login As New Form
Login.Show()
On your login form when in loading event:
Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WelcomeForm.Close()
End Sub
This will try to hide the first form and load the second form. And when second form is completely loaded it will try to close the first form.
Make sure that on your Application Tab under your Project properties the option is set to "When last form closes".
If you close sub main form from application, your application will close. However, you can close and open other forms if they are not the sub main form. Maybe you can just hide it instead.
You just need to put Hide() instead of Close :)
So for example, in the project im doing right now...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click // Button1.Click is your "continue" button
Hide()
LogInFrom.Show()
End Sub

how to automatically click search button in google visual basic . net

I have a form with textbox, button and a tabcontrol.
in the button I have this code :
[Dim browser As New WebBrowser()
TabPage1.Controls.Add(browser)
browser.Dock = DockStyle.Fill
browser.Navigate(New Uri("http://www.google.com"))]
The code above works, but I need to be able to search from my textbox and when I click the button it will take me to google and then automatically enter's the word I searched for in my textbox and then clicks the search on google button. I tried this but it does not work. Thanks
Dim textElement. As HtmlElement = browser.Document.All.GetElementsByName("q")(0)
textElement.SetAttribute("value", textbox.text")
Dim btnElement As HtmlElement = browser.Document.All.GetElementsByName("btnG")(0)
btnElement.InvokeMember("click")
I also needed to search in Google Browser with the text the User wanted and by adding the code below to the Button Click Event it did what I wanted.
Code:
Dim sInfo As New ProcessStartInfo("https://www.google.co.in/search?q=" & TXT_Entidade.Text)
Try
Process.Start(sInfo)
Catch ex As Exception
Process.Start("iexplore.exe", sInfo.FileName)
End Try
You'll need to set focus to the textElement before clicking the button.
textElement.Focus()
Otherwise, the page won't run the search apparently.
You can see this by trying the same basic steps you've got above in the Console window. They won't work until the field has had focus (from my testing).
(I also used the mshtml type library so that the click function was directly exposed in the full code below)
Imports mshtml
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
web.Navigate("http://www.google.com")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim textElement As HtmlElement = web.Document.All.GetElementsByName("q")(0)
textElement.SetAttribute("value", TextBox1.Text)
textElement.Focus()
Dim btnElement As HTMLButtonElement =
CType(web.Document.All.GetElementsByName("btnG")(0).DomElement,
HTMLButtonElement)
btnElement.click()
End Sub
End Class
I think you can use this in your button click handler...
browser.navigate("https://www.google.co.in/search?q="+textbox.Text)
This will search Google for the text in your Text Box.
You can search without "automatically clicking the search button" and you do not have to set the value in the text element of the html. This works for me. Hope this helps.

VB.net form restore not showing form

I'm currently using VB.Net 2008.
The project has the "make single instance application" checkbox checked.
The application works by hiding the form when the form is minimized.
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
Me.Hide()
End If
End Sub
When the appropriate menu item is pressed within the notifyicon the form should show itself again.
Private Sub ShowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles ShowToolStripMenuItem.Click
Me.Show()
Me.WindowState = FormWindowState.Normal
End Sub
This works fine until the user tries to open the same application while the form is minimized. When this occurs the application will block a new instance of the application the user was trying to open as expected, however when the user then goes to show the form from the notifyicon's menu it will have seemed to open (it shows the form in the taskbar) but no window is shown.
At this point the window can be maximized and works as intended but by using the restore button the window will not be drawn but will still be shown in the taskbar.
If any help can be given on how to restore the form correctly from being hidden it would be most appreciated.
Thanks in advance
Just a couple of suggestions...
Instead of using Hide() and Show(), could you use the ShowInTaskbar property of the form instead?
Set it to false where you use Hide() and true where you currently use Show(), and see if that makes any difference.
Or perhaps set the WindowState to Normal before calling Show().