当前位置: 代码迷 >> VBA >> VSTO编程,Excel2007的Worksheet_SelectionChange事件失效有关问题
  详细解决方案

VSTO编程,Excel2007的Worksheet_SelectionChange事件失效有关问题

热度:2760   发布时间:2013-02-26 00:00:00.0
VSTO编程,Excel2007的Worksheet_SelectionChange事件失效问题
具体测试:在Excel2007中按住向下(或向右键)移动一段时间后,Worksheet_SelectionChange事件就失效了,请高手帮我看看,代码如下:

C# code
    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    }


------解决方案--------------------------------------------------------
高见,顶