别总是急着找MS的bug嘛!先仔细读读MSDN吧:Command: A long integer specifying the identifier of the command that changed.
It can be one of the following constants or values.
Constant Value Meaning
CSC_UPDATECOMMANDS -1 The enabled state of a toolbar button may have changed; the Enable parameter should be ignored.
CSC_NAVIGATEFORWARD 1 The enabled state of the Forward button has changed.
CSC_NAVIGATEBACK 3 The enabled state of the Back button has changed.
Enable: A Boolean value that is TRUE if the command is enabled, or FALSE if not. 所以,command的值的确不可能是2,比如,你要知道什么时候不能再Forward了,那就是:(command == 1 && enable == false);
而不能Back则是: (command == 3 && enable == false);
It can be one of the following constants or values.
Constant Value Meaning
CSC_UPDATECOMMANDS -1 The enabled state of a toolbar button may have changed; the Enable parameter should be ignored.
CSC_NAVIGATEFORWARD 1 The enabled state of the Forward button has changed.
CSC_NAVIGATEBACK 3 The enabled state of the Back button has changed.
Enable: A Boolean value that is TRUE if the command is enabled, or FALSE if not. 所以,command的值的确不可能是2,比如,你要知道什么时候不能再Forward了,那就是:(command == 1 && enable == false);
而不能Back则是: (command == 3 && enable == false);
它只是不断返回command=1和enable=true。再次说明是在VS.NET Beta2中文版的VC#中。同时在对象浏览器中
查看过,当command==2 && enable==false时方法GoBack才不能。请各位多多发表意见。谢谢!!
[EXDISP.H]
typedef /* [helpstring][uuid] */
enum CommandStateChangeConstants
{ CSC_UPDATECOMMANDS = 0xffffffff,
CSC_NAVIGATEFORWARD = 0x1,
CSC_NAVIGATEBACK = 0x2 <-- GoBack是2
} CommandStateChangeConstants;我在.NET Final Release上试了一下,确实可以得到各种command=1/2, enable=ture/false的情况,应该是好的。由于没装Beta2,所以也没试。
不如升级到Final Release吧,既然是Beta,bug是难免的。:)
private void axWebBrowser1_DownloadComplete(object sender, System.EventArgs e)
{
label1.Text=this.back.ToString();
textBox2.Text=this.benable.ToString();
}private void axWebBrowser1_CommandStateChange(object sender, AxSHDocVw.DWebBrowserEvents2_CommandStateChangeEvent e)
{
this.back=e.command;
this.benable=e.enable;
}
按照你的代码,每次浏览都会有一个CommandStateChange丢失,也许恰好是Back的。:)bool canBack = false, canForward = false;
private void axWebBrowser1_CommandStateChange(object sender, AxSHDocVw.DWebBrowserEvents2_CommandStateChangeEvent e)
{
if (e.command == 1) canForward = e.enable;
if (e.command == 2) canBack = e.enable;
}