public Addin() { // trigger the well known IExtensibility2 methods, this is very similar to VSTO this.OnStartupComplete += new OnStartupCompleteEventHandler(Addin_OnStartupComplete); // wen can add our own taskpanes here, if you dont want that then overwrite the CTPFactoryAvailable method // show into the SamplePane.cs to see how you can use the NetOffice ITaskPane interface to get more control for Load/Unload and connect the host application TaskPanes.Add(typeof(SamplePane), "NetOffice Tools - Sample Pane"); TaskPanes[0].DockPosition = MsoCTPDockPosition.msoCTPDockPositionRight; TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal; TaskPanes[0].Width = 150; TaskPanes[0].Visible = true; TaskPanes[0].Arguments = new object[] { this }; }
/// <summary> /// creates an instance of the class /// </summary> public Addin() { Factory.Settings.ExceptionMessage = "#Error"; Factory.Console.Name = "CodeCommander"; this.OnStartupComplete += new OnStartupCompleteEventHandler(Addin_OnStartupComplete); this.OnDisconnection += new OnDisconnectionEventHandler(Addin_OnDisconnection); TaskPanes.Add(typeof(UI.DeveloperPane), "Code Commander"); TaskPanes[0].DockPosition = MsoCTPDockPosition.msoCTPDockPositionRight; TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNone; TaskPanes[0].Width = 320; TaskPanes[0].Visible = true; TaskPanes[0].Arguments = new object[] { this }; TaskPanes[0].VisibleStateChange += new CustomTaskPane_VisibleStateChangeEventHandler(TaskPane_VisibleStateChange); }
public void CallShimHost() { //MessageBox.Show("CallShimHost"); foreach (var item in TaskPanes.ToArray()) { if (null != item.Pane) { item.Pane.Delete(); } } if (null != ShimHost) { ShimHost.Update("Greetings from previous addin instance."); } else { MessageBox.Show("I dont have a shim host :("); } }
public Addin() { // Enable shared debug output and send a load message(use NOTools.ConsoleMonitor.exe to observe the shared console output) Factory.Console.EnableSharedOutput = true; Factory.Console.SendPipeConsoleMessage(null, "Addin has been loaded."); // We want observe the current count of open proxies with NOTools.ConsoleMonitor.exe Factory.Settings.EnableProxyCountChannel = true; // trigger the well known IExtensibility2 methods, this is very similar to VSTO this.OnStartupComplete += new OnStartupCompleteEventHandler(Addin_OnStartupComplete); // wen can add our own taskpanes here, if you dont want that then overwrite the CTPFactoryAvailable method // show into the SamplePane.cs to see how you can use the NetOffice ITaskPane interface to get more control for Load/Unload and connect the host application TaskPanes.Add(typeof(SamplePane), "NetOffice Tools - Sample Pane(CS4)"); TaskPanes[0].DockPosition = MsoCTPDockPosition.msoCTPDockPositionTop; TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange; TaskPanes[0].Height = 50; TaskPanes[0].Visible = true; TaskPanes[0].Arguments = new object[] { this }; TaskPanes[0].VisibleStateChange += new Office.CustomTaskPane_VisibleStateChangeEventHandler(TaskPane_VisibleStateChange); }
private void Addin_OnConnection(object app, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { try { _outlookApplication = new OutLook.Application(null, app); TaskPanes.Add(typeof(TaskPaneContainerControl), "侧边栏标题"); TaskPanes[0].DockPosition = MsoCTPDockPosition.msoCTPDockPositionBottom; TaskPanes[0].DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange; TaskPanes[0].Height = 100; TaskPanes[0].Visible = true; TaskPanes[0].Arguments = new object[] { this }; // register add signature after new mail var i = _outlookApplication.Inspectors as OutLook.Inspectors; if (i != null) { i.NewInspectorEvent += i_NewInspectorEvent; } } catch (Exception exception) { // 处理 } }
private void ProceedCustomPaneAttributes() { CustomPaneAttribute[] paneAttributes = AttributeHelper.GetCustomPaneAttributes(Type); foreach (CustomPaneAttribute itemPane in paneAttributes) { if (null != itemPane) { TaskPaneInfo item = TaskPanes.Add(itemPane.PaneType, itemPane.PaneType.Name); if (!CallOnCreateTaskPaneInfo(item)) { item.Title = itemPane.Title; item.Visible = itemPane.Visible; item.DockPosition = (Office.Enums.MsoCTPDockPosition)Enum.Parse(typeof(Office.Enums.MsoCTPDockPosition), itemPane.DockPosition.ToString()); item.DockPositionRestrict = (Office.Enums.MsoCTPDockPositionRestrict)Enum.Parse(typeof(Office.Enums.MsoCTPDockPositionRestrict), itemPane.DockPositionRestrict.ToString()); item.Width = itemPane.Width; item.Height = itemPane.Height; item.Arguments = new object[] { this }; } item.VisibleStateChange += new NetOffice.OfficeApi.CustomTaskPane_VisibleStateChangeEventHandler(AttributePane_VisibleStateChange); item.DockPositionStateChange += new Office.CustomTaskPane_DockPositionStateChangeEventHandler(AttributePane_DockPositionStateChange); } } }
/// <summary> /// ICustomTaskPaneConsumer implementation /// </summary> /// <param name="CTPFactoryInst">factory proxy from host application</param> public virtual void CTPFactoryAvailable(object CTPFactoryInst) { try { if (null == CTPFactoryInst) { Factory.Console.WriteLine("Warning: null argument recieved in CTPFactoryAvailable. argument name: CTPFactoryInst"); return; } CustomPaneAttribute paneAttribute = AttributeHelper.GetCustomPaneAttribute(Type); if (null != paneAttribute) { TaskPaneInfo item = TaskPanes.Add(paneAttribute.PaneType, paneAttribute.PaneType.Name); if (!CallOnCreateTaskPaneInfo(item)) { item.Title = paneAttribute.Title; item.Visible = paneAttribute.Visible; item.DockPosition = (Office.Enums.MsoCTPDockPosition)Enum.Parse(typeof(Office.Enums.MsoCTPDockPosition), paneAttribute.DockPosition.ToString()); item.DockPositionRestrict = (Office.Enums.MsoCTPDockPositionRestrict)Enum.Parse(typeof(Office.Enums.MsoCTPDockPositionRestrict), paneAttribute.DockPositionRestrict.ToString()); item.Width = paneAttribute.Width; item.Height = paneAttribute.Height; item.Arguments = new object[] { this }; } item.VisibleStateChange += new NetOffice.OfficeApi.CustomTaskPane_VisibleStateChangeEventHandler(AttributePane_VisibleStateChange); item.DockPositionStateChange += new Office.CustomTaskPane_DockPositionStateChangeEventHandler(AttributePane_DockPositionStateChange); } TaskPaneFactory = new NetOffice.OfficeApi.ICTPFactory(Factory, null, CTPFactoryInst); foreach (TaskPaneInfo item in TaskPanes) { string title = item.Title; Office.CustomTaskPane taskPane = TaskPaneFactory.CreateCTP(item.Type.FullName, title) as Office.CustomTaskPane; item.Pane = taskPane; item.AssignEvents(); item.IsLoaded = true; switch (taskPane.DockPosition) { case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionLeft: case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionRight: taskPane.Width = item.Width; break; case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionTop: case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionBottom: taskPane.Height = item.Height; break; case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionFloating: item.Width = paneAttribute.Width; taskPane.Height = item.Height; break; default: break; } ITaskPane pane = taskPane.ContentControl as ITaskPane; if (null != pane) { TaskPaneInstances.Add(pane); object[] argumentArray = new object[0]; if (item.Arguments != null) { argumentArray = item.Arguments; } pane.OnConnection(Application, taskPane, argumentArray); } foreach (KeyValuePair <string, object> property in item.ChangedProperties) { if (property.Key == "Title") { continue; } try { if (property.Key == "Width") // avoid to set width in top and bottom align { object outValue = null; item.ChangedProperties.TryGetValue("DockPosition", out outValue); if (null != outValue) { Office.Enums.MsoCTPDockPosition position = (Office.Enums.MsoCTPDockPosition)Enum.Parse(typeof(Office.Enums.MsoCTPDockPosition), outValue.ToString()); if (position == Office.Enums.MsoCTPDockPosition.msoCTPDockPositionTop || position == Office.Enums.MsoCTPDockPosition.msoCTPDockPositionBottom) { continue; } } } if (property.Key == "Height") // avoid to set height in left and right align { object outValue = null; item.ChangedProperties.TryGetValue("DockPosition", out outValue); if (null == outValue) { outValue = Office.Enums.MsoCTPDockPosition.msoCTPDockPositionRight; // NetOffice default position if unset } Office.Enums.MsoCTPDockPosition position = (Office.Enums.MsoCTPDockPosition)Enum.Parse(typeof(Office.Enums.MsoCTPDockPosition), outValue.ToString()); if (position == Office.Enums.MsoCTPDockPosition.msoCTPDockPositionLeft || position == Office.Enums.MsoCTPDockPosition.msoCTPDockPositionRight) { continue; } } taskPane.GetType().InvokeMember(property.Key, BindingFlags.SetProperty, null, taskPane, new object[] { property.Value }); } catch { ; } } } } catch (NetRuntimeSystem.Exception exception) { Factory.Console.WriteException(exception); OnError(ErrorMethodKind.CTPFactoryAvailable, exception); } }