Microsoft KB Archive/836128

= How to use Forward and Back buttons for the WebBrowser control in Visual Basic .NET and in Visual C# .NET =

Article ID: 836128

Article Last Modified on 5/17/2007

-

APPLIES TO


 * Microsoft Internet Explorer (Programming) 6 (SP1)

-



INTRODUCTION
When you host the WebBrowser control, you may want to implement a Forward button and a Back button. These buttons are similar to buttons that Microsoft Internet Explorer implements. This article explains the elements and the code that are used with the WebBrowser control to implement these buttons.



MORE INFORMATION
To overcome this problem, you can use the WebBrowser control with the CommandStateChange event. The CommandStateChange event is fired whenever the Forward button or the Back button must be either enabled or disabled. The CSC_NAVIGATEFORWARD constant and the CSC_NAVIGATEBACK constant indicate the type of action that the user wants.These constants are defined in the CommandStateChangeConstants enumerator. This enumerator is a member of the SHDocVw dynamic-link library (DLL).

Microsoft Visual Basic .NET sample code
Following is the Visual Basic .NET sample code that handles the CommandStateChange event. ' Visual Basic .NET sample code for handling the CommandStateChange event

Private Sub AxWebBrowser1_CommandStateChange(ByVal sender As Object,        ByVal e As AxSHDocVw.DWebBrowserEvents2_CommandStateChangeEvent) Handles AxWebBrowser1.CommandStateChange Select Case CType(e.command, CommandStateChangeConstants) Case CommandStateChangeConstants.CSC_NAVIGATEBACK btnBack.Enabled = e.enable Case CommandStateChangeConstants.CSC_NAVIGATEFORWARD btnForward.Enabled = e.enable End Select End Sub

Microsoft Visual C# .NET sample code
Following is the Visual C# .NET sample code that handles the CommandStateChange event. // Visual C# .NET sample code for handling the CommandStateChange event

private void axWebBrowser1_CommandStateChange(object sender,        AxSHDocVw.DWebBrowserEvents2_CommandStateChangeEvent e) { switch (CommandStateChangeConstants)e.command {       case CommandStateChangeConstants.CSC_NAVIGATEBACK: btnBack.Enabled=e.enable; break; case CommandStateChangeConstants.CSC_NAVIGATEFORWARD: btnForward.Enabled=e.enable; break; case default: break; } } Note The control that is used for the Forward button is the btnForward control. The control that is used for the Back button is the btnBack control.

