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.