Solved

Webbrowser enable/disable goback and goforward

Posted on 2004-10-08
6
1,046 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 12258315
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
ID: 12261331
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
ID: 12261996
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:oostwijk
ID: 12265161
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
ID: 12265885
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
ID: 12266325
That was it, thank you very much
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

756 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