|
using System;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
namespace ExcelInEditModeAddin
{
public partial class ThisAddIn
{
ExcelUtil.ExcelEditorModeEventPublisher _editorModeEventPublisher = null;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
#region VSTO generated code
this.Application = (Excel.Application)Microsoft.Office.Tools.Excel.ExcelLocale1033Proxy.Wrap(typeof(Excel.Application), this.Application);
_editorModeEventPublisher = new ExcelUtil.ExcelEditorModeEventPublisher(this.Application);
_editorModeEventPublisher.EditModeOn += _editorModeEventPublisher_EditModeOn;
_editorModeEventPublisher.EditModeOff += _editorModeEventPublisher_EditModeOff;
// CHECK THE STATUS IMMEDIATELLY
ReportEditorModeStatus(_editorModeEventPublisher.IsExcelInEditMode);
#endregion
}
private void ReportEditorModeStatus(bool _editorMode)
{
string report = string.Empty;
if (_editorMode)
report = "Excel is in editor mode now!";
else
report = "Excel is NOT in editor mode now!";
Application.StatusBar = report;
}
void _editorModeEventPublisher_EditModeOff(object sender, EventArgs e)
{
ReportEditorModeStatus(false);
}
void _editorModeEventPublisher_EditModeOn(object sender, EventArgs e)
{
ReportEditorModeStatus(true);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
_editorModeEventPublisher.EditModeOn -= _editorModeEventPublisher_EditModeOn;
_editorModeEventPublisher.EditModeOff -= _editorModeEventPublisher_EditModeOff;
_editorModeEventPublisher.Dispose();
_editorModeEventPublisher = null;
}
#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
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.