sorry if the title of my question was wrong.
I am using Visual Studio 2019
My problem is using a button that is not inside TabControl and like umm... The button outside the TabControl should work on selected tab only. But it doesn't, I tried doing like this:
WebBrowser1.GoBack()
There was no error at all, but when I debug it and press the button, it shows me the code and visual studio shows me something message. Anyways, I don't remember it.
Please help me, advance thanks to the helpers.
Edit:
Hello, people who don't understand my question correctly, I am going to show more information.
System.Runtime.InteropServices.COMException HResult=0x80004005
Message=Error HRESULT E_FAIL has been returned from a call to a COM component. Source=Interop.SHDocVw StackTrace: at SHDocVw.IWebBrowser2.GoBack() at AxSHDocVw.AxWebBrowser.GoBack()
at Browser.Browser.Button1_Click(Object sender, EventArgs e) in C:\Users\Admin\source\repos\Browser\Browser\Browser.vb:line 20 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at Browser.My.MyApplication.Main(String[] Args) in :line 81
Public Class Browser
Private Sub Button6_Click(sender As Object, e As EventArgs)
Form1.TabControl1.TabPages.Remove(Form1.TabControl1.SelectedTab)
End Sub
Private Sub NewTabToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewTabToolStripMenuItem.Click
Dim t As New TabPage
Dim tab As New Form1
tab.Show()
tab.Dock = DockStyle.Fill
tab.TopLevel = False
t.Controls.Add(tab)
Form1.TabControl1.TabPages.Add(t)
Form1.TabControl1.SelectTab(t)
AxWebBrowser1.Navigate("https://www.google.com")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
AxWebBrowser1.GoBack()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
AxWebBrowser1.GoForward()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
AxWebBrowser1.Navigate("https://www.google.com")
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
AxWebBrowser1.Refresh()
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
AxWebBrowser1.Navigate(ComboBox1.Text)
End Sub
Private Sub CloseTabToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CloseTabToolStripMenuItem.Click
Form1.TabControl1.TabPages.Remove(Form1.TabControl1.SelectedTab)
Me.Close()
End Sub
Private Sub ComboBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles ComboBox1.KeyDown
If e.KeyCode = Keys.Enter Then
Button3.PerformClick()
End If
End Sub
Private Sub ContextMenuStrip1_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening
ContextMenuStrip1.Show(Button6, 0, y:=Button6.Height)
End Sub
End Class
From the official documentation of Microsoft, I guess you wanted similar to .SelectedTab = TabNum
, an example's shown below:
Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TabControl1.SelectedTab Is TabPage1 ' choose your required statement
SpecificActivityForPage1() ' your code
Else If TabControl1.SelectedTab Is TabPage2
SpecificActivityForPage2() ' your code
Else
' something else...
End If
End Sub
This should work for you. If it doesn't, please specify your error message thrown by the IDE.
User contributions licensed under CC BY-SA 3.0