VB.net Form unexpectingly terminating - vb.net

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

Related

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 :)

Multi-pane browser window with VB.Net

I am trying to implement a project in VB.NET wherein a user can see two browser window panes side by side. It is very similar to placing two browser windows side by side on the screen, one docking to the left side, and the other on the right side. Only in this case, there's only one application. I'm having the following problems with my code
On pressing enter, the browser is not navigating to the website for both the panes
The controls on the left pane are not working. Only the Go button works for the left pane.
Here is my code (can't post pictures yet):
Public Class Form1
Dim int As Integer = 0
Dim int1 As Integer = 0
Private Sub Loading(ByVal sender As Object, ByVal e As Windows.Forms.WebBrowserProgressChangedEventArgs)
ToolStripProgressBar1.Maximum = e.MaximumProgress
ToolStripProgressBar1.Value = e.MaximumProgress
End Sub
Private Sub Loading1(ByVal sender1 As Object, ByVal e1 As Windows.Forms.WebBrowserProgressChangedEventArgs)
ToolStripProgressBar2.Maximum = e1.MaximumProgress
ToolStripProgressBar2.Value = e1.MaximumProgress
End Sub
Private Sub Done(ByVal sender As Object, ByVal e As Windows.Forms.WebBrowserDocumentCompletedEventArgs)
TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle
TextBox1.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString
End Sub
Private Sub Done1(ByVal sender1 As Object, ByVal e1 As Windows.Forms.WebBrowserDocumentCompletedEventArgs)
TabControl2.SelectedTab.Text = CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle
TextBox2.Text = CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Browser As New WebBrowser
TabControl1.TabPages.Add("New Page")
Browser.Name = "Web Browser"
Browser.Dock = DockStyle.Fill
TabControl1.SelectedTab.Controls.Add(Browser)
AddHandler Browser.ProgressChanged, AddressOf Loading
AddHandler Browser.DocumentCompleted, AddressOf Done
int = int + 1
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(My.Settings.homePage)
Dim Browser1 As New WebBrowser
TabControl2.TabPages.Add("New Page")
Browser1.Name = "Web Browser 2"
Browser1.Dock = DockStyle.Fill
TabControl2.SelectedTab.Controls.Add(Browser1)
AddHandler Browser1.ProgressChanged, AddressOf Loading1
AddHandler Browser1.DocumentCompleted, AddressOf Done1
int1 = int1 + 1
CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).Navigate(My.Settings.homePage)
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim Browser As New WebBrowser
TabControl1.TabPages.Add("New Page")
TabControl1.SelectTab(int)
Browser.Name = "Web Browser"
Browser.Dock = DockStyle.Fill
TabControl1.SelectedTab.Controls.Add(Browser)
AddHandler Browser.ProgressChanged, AddressOf Loading
AddHandler Browser.DocumentCompleted, AddressOf Done
int = int + 1
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(My.Settings.homePage)
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Not TabControl1.TabPages.Count = 1 Then
TabControl1.TabPages.RemoveAt(TabControl1.SelectedIndex)
TabControl1.SelectTab(TabControl1.TabPages.Count - 1)
int = int - 1
End If
End Sub
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs)
If e.KeyCode = Keys.Enter Then
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(TextBox1.Text)
End If
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).ShowPropertiesDialog()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoBack()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoForward()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Refresh()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Stop()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(My.Settings.homePage)
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(TextBox1.Text)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ToolStripStatusLabel1.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).StatusText
End Sub
Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
Dim Browser1 As New WebBrowser
TabControl2.TabPages.Add("New Page")
TabControl2.SelectTab(int1)
Browser1.Name = "Web Browser 2"
Browser1.Dock = DockStyle.Fill
TabControl2.SelectedTab.Controls.Add(Browser1)
AddHandler Browser1.ProgressChanged, AddressOf Loading1
AddHandler Browser1.DocumentCompleted, AddressOf Done1
int1 = int1 + 1
CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).Navigate(My.Settings.homePage)
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
If Not TabControl2.TabPages.Count = 1 Then
TabControl2.TabPages.RemoveAt(TabControl2.SelectedIndex)
TabControl2.SelectTab(TabControl2.TabPages.Count - 1)
int1 = int1 - 1
End If
End Sub
Private Sub TextBox2_KeyDown(sender As Object, e As KeyEventArgs)
If e.KeyCode = Keys.Enter Then
CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).Navigate(TextBox2.Text)
End If
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).ShowPropertiesDialog()
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).GoBack()
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).GoForward()
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).Refresh()
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).Stop()
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).Navigate(My.Settings.homePage)
End Sub
Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).Navigate(TextBox2.Text)
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
ToolStripStatusLabel2.Text = CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).StatusText
End Sub
End Class
I'm new here so I'm sorry if I missed out anything. Any help would be appreciated. Thank you.
EDIT: I tried implementing the same thing with a single pane, much like implementing a simple tabbed browser in Visual Studio 2013. Same result. Only GO button works, and enter key does not produce anything.
If e.KeyCode = Keys.Enter Then
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(TextBox1.Text)
End If
You only calling navigate in TabControl1 (or 2). You need to call all from each of the TextBoxX_KeyDown Handlers.
If e.KeyCode = Keys.Enter Then
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(TextBox1.Text)
CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).Navigate(TextBox2.Text)
End If

VB.Net Web Browser controls not working

I'm trying to implement a simple web browser in Visual Studio 2013 using VB.Net. However, when I run the application, only the GO button works, and none of the other functions are firing, except for the Form1_Load function. Please help me.
Here is my code:
Public Class Form1
Dim int As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("www.google.com")
End Sub
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs)
If e.KeyCode = Keys.Enter Then
WebBrowser1.Navigate(TextBox1.Text)
End If
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
WebBrowser1.ShowPropertiesDialog()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
WebBrowser1.GoBack()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
WebBrowser1.GoForward()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
WebBrowser1.Refresh()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
WebBrowser1.Stop()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
WebBrowser1.Navigate("www.google.com")
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
WebBrowser1.Navigate(TextBox1.Text)
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
End Sub
End Class
You need to add the Handles Button1.Click, Handles Button2.Click, etc to each sub

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.