/// <summary> /// ICustomTaskPaneConsumer implementation /// </summary> /// <param name="CTPFactoryInst">factory proxy from host application</param> public virtual void CTPFactoryAvailable(object CTPFactoryInst) { try { if (null != CTPFactoryInst) { 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; 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") { taskPane.GetType().InvokeMember(property.Key, BindingFlags.SetProperty, null, taskPane, new object[] { property.Value }); } } } } } catch (NetRunTimeSystem.Exception exception) { NetOffice.DebugConsole.Default.WriteException(exception); OnError(ErrorMethodKind.CTPFactoryAvailable, exception); } }
public void CTPFactoryAvailable(object CTPFactoryInst) { try { Office.ICTPFactory ctpFactory = new NetOffice.OfficeApi.ICTPFactory(_accessApplication, CTPFactoryInst); Office._CustomTaskPane taskPane = ctpFactory.CreateCTP(typeof(Addin).Assembly.GetName().Name + ".SampleControl", "NetOffice Sample Pane(CS35)", Type.Missing); taskPane.DockPosition = MsoCTPDockPosition.msoCTPDockPositionRight; taskPane.Width = 300; taskPane.Visible = true; _sampleControl = taskPane.ContentControl as SampleControl; ctpFactory.Dispose(); } catch (Exception exception) { string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, exception.Message); MessageBox.Show(message, _progId, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void CTPFactoryAvailable(object CTPFactoryInst) { try { Office.ICTPFactory ctpFactory = new NetOffice.OfficeApi.ICTPFactory(_outlookApplication, CTPFactoryInst); Office._CustomTaskPane taskPane = ctpFactory.CreateCTP(typeof(Addin).Assembly.GetName().Name + ".SampleControl", "NetOffice Sample Pane(CS4)", Type.Missing); taskPane.DockPosition = MsoCTPDockPosition.msoCTPDockPositionRight; taskPane.Width = 300; taskPane.Visible = true; _sampleControl = taskPane.ContentControl as SampleControl; ctpFactory.Dispose(); } catch (Exception exception) { string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, exception.Message); MessageBox.Show(message, _prodId, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <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); } }
/// <summary> /// ICustomTaskPaneConsumer implementation /// </summary> /// <param name="CTPFactoryInst">factory proxy from host application</param> public virtual void CTPFactoryAvailable(object CTPFactoryInst) { try { if (null != CTPFactoryInst) { 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; 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") taskPane.GetType().InvokeMember(property.Key, BindingFlags.SetProperty, null, taskPane, new object[] { property.Value }); } } } catch (NetRunTimeSystem.Exception exception) { NetOffice.DebugConsole.Default.WriteException(exception); OnError(ErrorMethodKind.CTPFactoryAvailable, exception); } }
public void CTPFactoryAvailable(object CTPFactoryInst) { try { _myCtpFactory = new NetOffice.OfficeApi.ICTPFactory(_excelApplication, CTPFactoryInst); _myPane = _myCtpFactory.CreateCTP("ExcelAddinCSharp.SampleControl", "NetOffice Sample Pane(C#)", Type.Missing); _myPane.DockPosition = MsoCTPDockPosition.msoCTPDockPositionRight; _myPane.Visible = true; _myControl = _myPane.ContentControl as SampleControl; _taskPanePassed = true; } catch (Exception throwedException) { _taskPanePassed = false; string details = string.Format("{1}{1}Details:{1}{1}{0}", throwedException.Message, Environment.NewLine); Console.WriteLine(details); } }