Solved

Webbrowser enable/disable goback and goforward

Posted on 2004-10-08
6
961 Views
Last Modified: 2008-01-09
I've got a webbrowser control in my application and now how too navigate and goback a page and goforward a page.

Now I want too disable the go back button in my program if there is no page to go back too and i want too disable the forward button in my program if there is no page too go forward too. How can I check if there are pages too go back or forward too ?
0
Comment
Question by:oostwijk
  • 3
  • 3
6 Comments
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
Private Const CSC_NAVIGATEFORWARD As Long = 1
Private Const CSC_NAVIGATEBACK As Long = 2
From MS:

"The WebBrowser control supports a CommandStateChange event, which is fired whenever the Forward or Back buttons need to be enabled or disabled. "

http://support.microsoft.com/default.aspx?scid=kb;EN-US;163282

' A Visual Basic application can also implement this
' functionality in this manner:  

Private Const CSC_NAVIGATEFORWARD As Long = 1
Private Const CSC_NAVIGATEBACK As Long = 2

Private Sub WebBrowser_CommandStateChange(ByVal Command As Long,ByVal Enable As Boolean)

       Select Case Command

           Case CSC_NAVIGATEBACK
               YourBackButtonName.Enabled = Enable

           Case CSC_NAVIGATEFORWARD
              YourForwardButtonName.Enabled = Enable

       End Select

End Sub
0
 

Author Comment

by:oostwijk
Comment Utility
hmm, this is difficult for me too understand.. im sort of a VB newbie...

I understand that it checks if the back or forward button needs too be enabled.

Where in the code can I disable the buttons if the back or forward function isnt available ?
0
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
The webbrowser control fires the CommandStateChange event when the enabled state of the command buttons you are using to control navigation need to be changed.

For example if youur webbrowser control's name is WebBrowser1 then the event would be:

Private Sub WebBrowser1_CommandStateChange(ByVal Command As Long,ByVal Enable As Boolean)
           Select Case Command

           Case CSC_NAVIGATEBACK
               YourBackButtonName.Enabled = Enable '<<< This enables or disables the button.  
                                                                                 Replace "YourBackButtonName" with the name of your button

           Case CSC_NAVIGATEFORWARD
              YourForwardButtonName.Enabled = Enable

       End Select
End Sub

And if the button you use to navigate forward is called cmdNavFwd, then to navigate forward in the click event:

Private Sub cmdNavFwd_Click()
    Webbrowser1.GoForward
End Sub
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:oostwijk
Comment Utility
ok, here is what I got, I've placed an webbrowser control on the form along with 2 commandbuttons named back and forward. And this is the code I have:

=========================================

Private Const CSC_NAVIGATEFORWARD As Long = 1
Private Const CSC_NAVIGATEBACK As Long = 2

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

Private Sub back_Click()
WebBrowser1.GoBack
End Sub

Private Sub Form_Load()
WebBrowser1.Navigate "http://www.cnn.com"
End Sub

Private Sub forward_Click()
WebBrowser1.GoForward
End Sub

============================================

If you try this code you can see nothing at all happens with the commandbuttons, they are not enabled or disabled. What am I doing wrong ?
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
Comment Utility
Private Sub WebBrowser1_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)
----------------------------^ Don't forget the 1, Webbrowser1 is the name of your control.

Try correcting this and see if it works for you.

In the code edit window there is a dropdown box upper left which lists objects on your form.  Select Webbrowser1, and then the dropdown box upper right will list all the available events for the control.

Hope it helps!
0
 

Author Comment

by:oostwijk
Comment Utility
That was it, thank you very much
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now