Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

He there.

 

I am a beginer in vb and I'am trying to use the tabcontro.The problem is that I can't use it. :)

 

I have this tabcontrol (tab) with two options.

I have a web browser control (web)

 

now...when I make a click on tabpage1 to go url1 ,and when I click on tabpage 2 to go url 2 in the web browser.

 

I tried to put a click event to tabpage1 like :

 

Private Sub TabPage1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabPage1.Click

web.Navigate("http://www.microsoft.com")

End Sub

 

and similary to tab page2 ..

 

whay this don't work ?

 

thanks a lot.

Posted

Without seeing more code it's really too hard to see what's wrong. What you've posted looks fine to me.. IF web.Navigate works okay and you've setup the tab pages correctly, etc.

 

Pete

  • *Experts*
Posted
Use the TabControl.SelectedIndexChanged event. The TabPage's click event only fires (as far as I know) when you click on the background of the tab - not when you change the tab selected.
Posted
Without seeing more code it's really too hard to see what's wrong. What you've posted looks fine to me.. IF web.Navigate works okay and you've setup the tab pages correctly, etc.

 

Pete

 

What more code ??

 

I need to write some code for tabpages? I just define them in proprieties window. tab1 and tab2.....

 

thanks

 

ps. how I use TabControl.SelectedIndexChanged ? ..I need somehow to link this with tab pages....but how ??

 

I know ..I know...but I am a beginner :)

Posted

to use the selected index changed

 

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged

If TabControl1.SelectedIndex = 0 Then

'User clicked Tab1

'do what ever you want here

ElseIf TabControl1.SelectedIndex = 1 Then

'User clicked tab2

'do what ever you want here

End If

End Sub

 

Hope this helps,

Dream as if you'll live forever, live as if you'll die today
  • 4 weeks later...
Posted

thanks , but I have some weird problems here...

 

If I have:

 

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged

If TabControl1.SelectedIndex = 1 Then

web1.Navigate2("http://some url.")

ElseIf TabControl1.SelectedIndex = 2 Then

web1.Navigate2("http://some url.")

End If

End Sub

 

... Is working....when I change de second an thirth tab ..the url is changing there....but I need this to work on first tab and second , so I need the code below....right ???

 

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged

If TabControl1.SelectedIndex = 0 Then

web1.Navigate2("http://some url.")

ElseIf TabControl1.SelectedIndex = 1 Then

web1.Navigate2("http://some url.")

End If

End Sub

 

but with this code .... index 0 changed....etc... I ceive this error at compilation:

 

An unhandled exception of type 'InvalidActiveXStateException' occurred in axinterop.shdocvw.dll

 

what this means ??? thanks.

Posted

OK try this

 

Add a private variable

 

Private FinishedLoading as Boolean = False

 

Then in your Form_Load event add befor End Sub

FinishedLoading = True

 

Then your selectedIndexChanged will be like this

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged

If FinishedLoading Then

If TabControl1.SelectedIndex = 0 Then

web1.Navigate2("http://some url.")

ElseIf TabControl1.SelectedIndex = 1 Then

web1.Navigate2("http://some url.")

End If

 

Hope this helps

End If

End Sub

Dream as if you'll live forever, live as if you'll die today
Posted

hi.

 

You will not going to belive that..but....now is working with a verry simple modification in my code.

 

I replaced "Private Sub TabControl1_SelectedIndexChanged" with Private Sub TabControl1_click" behavior and now is working even if I put 0

 

...weird anyway...

 

but all the thanks...who knows when I will need your advice.

Posted
The code i gave you will also work. The reason that error is happening is that the SelectedINdexChanged is called while the control is being initialized. And then the event is executed but maybe the Web control has not been initialized so an exception occurs. Converting it to the click solved it because a click event isnot raised while the control is being initialized. Adding the variable i told you about will force the code in the Selected Index Changed to not to execute until the form has finished loading.
Dream as if you'll live forever, live as if you'll die today

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...