Show Form2 7seconds delayed after Form1 close - vb.net

I have two forms in my application, form2 is shown on clicking a button in the form1. but i need a delay of 7 seconds between form1's close and form2's show for that i wrote the following code:
Public Class Form1
Dim i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
i = 0
Me.Close()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
i += 1
If i = 7 Then
Form1.Show()
End If
End Sub
End Class
But it does not give me the result. form2 not shown at all. what was the mistake i had made in the code? can anyone help me?
Thanks in advance.

When there's no active form left in a Windows Forms application, the application will quit. Therefore, you might want to hide the main form instead of closing it:
Me.Hide()

i think no need of unnecessary declaration for time delay because you can simply set it on your timer control itself
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 7000
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Form2.Show()
Me.Close()
End Sub
End Class
or
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 7000
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Close()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Form2.Show()
End Sub

Related

How do I get the parent form from a child form in VB.net?

I have a VB form which may be called by a number of forms. Upon exiting this child form, I want to restore the calling form but I cannot seem to figure out how to determine which form called it. Any help would be greatly appreciated.
You can create a tagging for parent forms (maybe a global array) which you will update the value every time you open a child form. You just have to remember which form is which on the tagging you will make.
Maybe you can try this-
Module with form tagging:
Module Module1
Public parentForms(2) As String
'parentForms(0) - parent form of Form 1
'parentForms(1) - parent form of Form 2
'parentForms(2) - parent form of Form 3
Public Sub openParentForm(ByVal ParentTag As String)
If ParentTag {use the notequal operator} "" Then
Select Case ParentTag
Case Form1.Tag
Form1.Show()
Case Form2.Tag
Form2.Show()
Case Form3.Tag
Form3.Show()
End Select
End If
End Sub
End Module
Form1:
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Tag = "Form1"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
parentForms(1) = Me.Tag
Form2.Show()
'Dont use .Close as the Parent Form will be disposed and the whole application will exit
Me.Visible = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
parentForms(2) = Me.Tag
Form3.Show()
Me.Visible = False
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Call openParentForm(parentForms(0))
End Sub
End Class
Form2
Public Class Form2
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Tag = "Form2"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
parentForms(0) = Me.Tag
Form1.Show()
Me.Visible = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
parentForms(2) = Me.Tag
Form3.Show()
Me.Visible = False
End Sub
Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Call openParentForm(parentForms(1))
End Sub
End Class
Form3
Public Class Form3
Private Sub Form3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Tag = "Form3"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
parentForms(0) = Me.Tag
Form1.Show()
Me.Visible = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
parentForms(1) = Me.Tag
Form2.Show()
Me.Visible = False
End Sub
Private Sub Form3_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Call openParentForm(parentForms(2))
End Sub
End Class

How can I toggle fullscreen for the embedded VLC player

I am embedding the VLC media player into a Windows Forms application through an activeX control.
The code goes like this:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Open file button
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Title = "Open file"
If openFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
AxVLCPlugin21.playlist.add(openFileDialog1.FileName)
End If
openFileDialog1.Dispose()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'Play button
AxVLCPlugin21.playlist.play()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'Stop button
AxVLCPlugin21.playlist.stop()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Pause button
AxVLCPlugin21.playlist.togglePause()
End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
'Volume control
AxVLCPlugin21.audio.Volume = TrackBar1.Value
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
'Toggle Full Screen button
AxVLCPlugin21.video.toggleFullscreen()
End Sub
End Class
How can I toggle full screen?
This code makes no effect:
AxVLCPlugin21.video.toggleFullscreen()
Thank you.
if (axVLCPlugin21.video.fullscreen)
axVLCPlugin21.video.fullscreen = false;
else
axVLCPlugin21.video.fullscreen = true;

Ask before delete vb express 2008

I've added a delete button to delete data from DataGridView and it deletes right away but I wanted to ask if you would like to delete before it deletes. How do I add this function to this button?
This is my code so far:
Private Sub Table_RKMBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.Table_RKMBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.RKM_System_dataDataSet)
End Sub
Private Sub Management_Window_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'RKM_System_dataDataSet.Table_RKM' table. You can move, or remove it, as needed.
Me.Table_RKMTableAdapter.Fill(Me.RKM_System_dataDataSet.Table_RKM)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Table_RKMBindingSource.AddNew()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Table_RKMBindingSource.EndEdit()
Table_RKMTableAdapter.Update(Me.RKM_System_dataDataSet.Table_RKM)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Table_RKMBindingSource.RemoveCurrent()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Table_RKMBindingSource.EndEdit()
Search_Window.Show()
Table_RKMTableAdapter.Update(Me.RKM_System_dataDataSet.Table_RKM)
Me.Close()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.WindowState = FormWindowState.Minimized
End Sub
Private Sub Table_RKMDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Table_RKMDataGridView.CellContentClick
End Sub
Thank you.
You can use a message box:
On your Button3_Click event add the following code:
Dim answer as Integer
answer = MessageBox.Show("Your Message", "Your title", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
If not answer = 6 then Table_RKMBindingSource.RemoveCurrent()
That should work :)

VB.net Form unexpectingly terminating

Hi I have the following form but cant figureout why its upbrubtly terminiating when difrent buttons are clicked?
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub button1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
Dim TEST1 As Integer = System.IO.Directory.GetFiles("C:\test\test").Length
If TEST1 = 0 Then
Me.WebBrowser1.Navigate("http://www.hotmail.com")
End If
End Sub
Private Sub button1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Me.WebBrowser1.Navigate("http://WWW.facebook.com")
End Sub
Private Sub button2_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseLeave
Me.WebBrowser1.Navigate("http://WWW.facebook.com")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.WebBrowser1.Navigate("file://C:\test\test")
Button1.Enabled = False
Button2.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.WebBrowser1.Navigate("file://C:\test")
Button2.Enabled = False
Button1.Enabled = True
End Sub
Private Sub button2_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseEnter
Dim TEST2 As Integer = System.IO.Directory.GetFiles("C:\test\test").Length
If TEST2 = 0 Then
Me.WebBrowser1.Navigate("http://www.hotmail.com")
End If
End Sub
The terms face book and hotmail are just random to keep company site private :)
I suspect the Mouse_Enter event and the Mouse_Leave events are not giving time to the webbrowser to fully load the document and maybe it is internally crashing.
Try checking if the webbrowser has finished working before navigating again and tell us:
Use
If WebBrowser1.ReadyState = WebBrowserReadyState.Complete
Me.WebBrowser1.Navigate("http://www.google.com")
End if

Showing a message to the user if website does not open

I'm trying to show a message to the user if the requested website does not open (or the internet is not working). The message I want to show is
"Site is not working. Please contact the administrator."
How can I do this? Here's what I have
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("google.com")
Dim connectn As Boolean
If connectn = False Then
MsgBox("site not working please contact the developer")
End If
End Sub
Private Sub Back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Back.Click
WebBrowser1.GoBack()
End Sub
Private Sub Forward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Forward.Click
WebBrowser1.GoForward()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
WebBrowser1.Stop()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
WebBrowser1.GoHome()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
WebBrowser1.Refresh()
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
End Sub
Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
End Sub
Private Sub WebBrowser1_DocumentCompleted_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
End Sub
End Class
It's best not to use the DocumentCompleted event handler as it will fire when a frame is complete, not necessarily the entire webpage. Instead use the following:
With WebBrowser1
.Navigate("google.com")
Do Until Not (.IsBusy)
Application.DoEvents()
Loop
Do Until .ReadyState = WebBrowserReadyState.Complete
Application.DoEvents()
Loop
End With
Other than that, if it is for a specific site you can find what the correct URL is and simply compare the "endstate" URL when the Webbrowser has completely loaded. If you want it to be generalized for any website you can find most information from this link about page event handling for navigation errors.