自定义任务窗格仅在卸载和重新加载AddIn时出现 [英] Custom Task Pane appearing only upon unloading and reloading the AddIn

查看:226
本文介绍了自定义任务窗格仅在卸载和重新加载AddIn时出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图开发一个自定义任务窗格,如下所示:

While I tried to develop a Custom Task Pane as reflected on:

https://msdn.microsoft.com/en-us/library/bb608590.aspx

https://msdn.microsoft.com/en-us/library/bb608590.aspx

我很惊讶地发现同样的事情从未出现过。只有卸载所说的COM AddIn并从Excel重新加载才能使Ribbon Toggle Button开始工作。

I was surprised to find that the same never did appear. It is only upon Unloading the said COM AddIn and reloading from the Excel that the Ribbon Toggle Button starts to work.

可能是什么原因和解决方案?

What could be the reason and solution?

推荐答案

您好
Faraz A. Qureshi,

我尝试引用该链接并尝试重现该问题。

I try to refer the link and try to reproduce the issue on my side.

我发现链接中提到的代码工作正常,并且正确隐藏/显示任务窗格。

I find that code mentioned in the link is working fine and it is hide / show the task pane properly.

所以有可能你没有使用正确编码,以便它不适合您。

so it is possible that you did not use the code properly, so that it is not working on your side.

您可以参考我的测试步骤来解决问题。

you can refer my testing steps to solve the issue.

(1)创建一个新的Excel Addin项目。

(1) create a new Excel Addin project.

(2)添加一个功能区和一个用户控件。

(2) Add one Ribbon and one user control.

(3)向功能区添加一个切换按钮。

(3) Add one Toggle Button to the Ribbon.

(4)在"ThisAddin.cs"中添加/替换下面的代码。文件。

(4) Add / replace below code in "ThisAddin.cs" file.

public partial class ThisAddIn
    {
        private UserControl1 taskPaneControl1;
        private Microsoft.Office.Tools.CustomTaskPane taskPaneValue;


        public Microsoft.Office.Tools.CustomTaskPane TaskPane
        {
            get
            {
                return taskPaneValue;
            }
        }




        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            taskPaneControl1 = new UserControl1();
            taskPaneValue = this.CustomTaskPanes.Add(
                taskPaneControl1, "MyCustomTaskPane");
            taskPaneValue.VisibleChanged +=
                new EventHandler(taskPaneValue_VisibleChanged);
        }
        private void taskPaneValue_VisibleChanged(object sender, System.EventArgs e)
        {
            Globals.Ribbons.Ribbon1.toggleButton1.Checked =
                taskPaneValue.Visible;
        }


        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

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

(5)添加切换按钮的点击事件并在下面添加代码。

(5) Add click event of Toggle Button and add code below.

 private void toggleButton1_Click(object sender, RibbonControlEventArgs e)
        {
            Globals.ThisAddIn.TaskPane.Visible = ((RibbonToggleButton)sender).Checked;

        }

(6)运行项目并单击功能区中的切换按钮以隐藏/显示任务窗格。

(6) Run the project and click the Toggle Button in Ribbon to hide/ show the Task Pane.

输出:

因此请尝试正确实施代码以使其正常工作。

so try to implement the code properly to make it work.

问候

Deepak


这篇关于自定义任务窗格仅在卸载和重新加载AddIn时出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆