VSTO编程,Excel2007的Worksheet_SelectionChange事件失效问题
具体测试:在Excel2007中按住向下(或向右键)移动一段时间后,Worksheet_SelectionChange事件就失效了,请高手帮我看看,代码如下:
public partial class ThisAddIn { private void ThisAddIn_Startup(object sender, System.EventArgs e) { this.Application.Worksheets[1].SelectionChange += new Excel.DocEvents_SelectionChangeEventHandler(Worksheet_SelectionChange); this.Application.SheetActivate += new Excel.AppEvents_SheetActivateEventHandler(Application_SheetActivate); } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { } private void Worksheet_SelectionChange(Excel.Range target) { this.Application.StatusBar = "选中的单元格内容为:" + string.Format("Address:{0}, Value:{1}, Value2:{2}", target.Address, target.Value, target.Value2); } private void Application_SheetActivate(object obj) { this.Application.ActiveSheet.SelectionChange += new Excel.DocEvents_SelectionChangeEventHandler(Worksheet_SelectionChange); } #region VSTO generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } #endregion }