Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Webbrowser enable/disable goback and goforward

Posted on 2004-10-08
6
Medium Priority
?
1,193 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

618 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