anyone know how you can detect whether there are any pages in the webbrowser control's history so that i can enable/disable the back/forward buttons?
Printable View
anyone know how you can detect whether there are any pages in the webbrowser control's history so that i can enable/disable the back/forward buttons?
Try this:
Code:Private Sub WebBrowser1_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)
On Error Resume Next
Select Case Command
Case CSC_NAVIGATEFORWARD
If Enable = True Then
'Forward dispo
ForwardEnable = True
RaiseEvent ForwardUpdate(True)
Else
'Forward non dispo
ForwardEnable = False
RaiseEvent ForwardUpdate(False)
End If
'Pas de forward
Case CSC_NAVIGATEBACK
If Enable = True Then
BackEnable = True
RaiseEvent BackUpdate(True)
'Back dispo
Else
BackEnable = False
RaiseEvent BackUpdate(False)
'Back non dispo
End If
End Select
If Command = -1 Then Exit Sub
'End If
End Sub
or this....SHorter...faster...better...Stronger!....(oh wait...that's the Bionic Man :rolleyes: )
Code:Private Sub WB_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)
On Error Resume Next
DoEvents
If Enable = True And Command = CSC_NAVIGATEBACK Then
cmdBack.Enabled = True
Elseif Enable = False And Command = CSC_NAVIGATEBACK Then
cmdBack.Enabled = False
End If
If Enable = True And Command = CSC_NAVIGATEFORWARD Then
cmdFwd.Enabled = True
Elseif Enable = False And Command = CSC_NAVIGATEFORWARD Then
cmdFwd.Enabled = False
End If
End Sub
VBBrowser v2.2.1
Shorter Yet:D
Code:Private Sub WebBrowser_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)
Select Case Command
Case CSC_NAVIGATEBACK
Back.Enabled = Enable
Case CSC_NAVIGATEFORWARD
Forward.Enabled = Enable
End Select
End Sub
ah ha! thanks guys :)
Bloodeye...Then your buttons will never be disabled?
The frwd button in particular...
sometimes it should be.
geoff -
I forgot to tell you that you need to start with the "Back" and "Forward" buttons disabled.
I got the my above example from Microsoft. The VB code is at the bottom of the example...difficult to see because the format is all garbled up. I noticed they don't mention anything about haveing the buttons disabled...I must have picked that up somewhere else.
Here's the code that I use. Pretty much the same as the MS example.
Code:Private Sub brwWb_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)
If Command = 2 Then
cmdNav(0).Enabled = Enable
End If
If Command = 1 Then
cmdNav(1).Enabled = Enable
End If
End Sub
i was just wondering how it would reacte when:
u use the back button...then the frwd btn is enabled...
if you then click forward...the frwd button should then be disabled again.
?? will that happen?
Everything works fine for me.
Keep in mind that you need to start with both buttons disabled. Then the CommandStateChange event indicates when either button should be enabled or disabled from the (ByVal Enable as Boolean) operator. "Enable" can be either True of False.
<HOMER> DOH! </HOMER>
Omg...ok..that must be one of the most obvious things I have overlooked. :rolleyes:
thanks for the wake up slap Bloodeye...
:)