如何禁用自定义任务窗格的调整大小和关闭按钮?

发布于 2024-11-07 10:22:49 字数 142 浏览 5 评论 0原文

如何防止 Office 自定义任务窗格调整大小,以便它始终具有尺寸并且无法使用“关闭”按钮关闭。

myCustomTaskPane.Height = 500;
myCustomTaskPane.Width = 500;

How can I prevent an Office Custom Task Pane for resizing, so that it's only and always have the dimensions and can't be closing with the "close" button.

myCustomTaskPane.Height = 500;
myCustomTaskPane.Width = 500;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

—━☆沉默づ 2024-11-14 10:22:49

至于调整大小,只需监视任务窗格的调整大小事件并重置大小即可。但是,您可能会考虑+为什么+您想要这样做。如果任务窗格有最小必要大小,则限制最小大小可能更有意义。如果内容可以调整大小,也许应该如此。

您还可以重写 OnLayout 方法。这通常会效果更好。

对于“关闭”按钮,我认为您需要拦截“VisibleChanged”事件并使窗格可见(如果它已隐藏)。我记得,任务窗格本身实际上并不是“关闭”的,只是设置为不可见。

As far as the resize, just monitor your task pane's resize event and reset the size. However you might consider +why+ you'd want to do that. If there's a minimum necessary size for your taskpane, it might make more sense to restrict the minimum. and if the contents are resizable, maybe they should be.

You might also override the OnLayout method. That will often work better.

For the Close button, I think you'd want to intercept the "VisibleChanged" event and make the pane visible if it's been hidden. As I recall, taskpanes are not actually "closed" per se, but just set invisible.

爱殇璃 2024-11-14 10:22:49

其中 _tp 是对任务窗格(不是 CustomTaskPane 容器)的引用,_ctp 是 CustomTaskPane 容器,iw 是 InspectorWrapperDictionary:

 void _tpvals_VisibleChanged(object sender, System.EventArgs e)
        {
            _tp.tmr.Start();
        }

并且,在任务窗格代码中:

public Timer tmr;

        public taskpane()
        {
            InitializeComponent();

            tmr = new Timer() { Interval = 500 };
            tmr.Tick += new EventHandler(tmr_Tick);
            tmr.Enabled = true;
            tmr.Stop();
        }


void tmr_Tick(object sender, EventArgs e)
        {
            if (iw == null)
                setVars();

            if (_tp.lv_AttachmentList.Items.Count > 0)
                _ctp.Visible = true;

            tmr.Stop();
        }

setvars() 是一个命令,用于拉入正确的 iw 并设置对 _tp 和 _ctp 的引用

Where _tp is a reference to your task pane (not the CustomTaskPane container), _ctp is the CustomTaskPane container, iw is the InspectorWrapperDictionary:

 void _tpvals_VisibleChanged(object sender, System.EventArgs e)
        {
            _tp.tmr.Start();
        }

And, in your task pane code:

public Timer tmr;

        public taskpane()
        {
            InitializeComponent();

            tmr = new Timer() { Interval = 500 };
            tmr.Tick += new EventHandler(tmr_Tick);
            tmr.Enabled = true;
            tmr.Stop();
        }


void tmr_Tick(object sender, EventArgs e)
        {
            if (iw == null)
                setVars();

            if (_tp.lv_AttachmentList.Items.Count > 0)
                _ctp.Visible = true;

            tmr.Stop();
        }

setvars() is a command to pull in the proper iw and set the references to _tp and _ctp

暗地喜欢 2024-11-14 10:22:49

我找到了一个解决方案:

void NormalizeSize(object sender, EventArgs e)
    {
        if (this.taskPane.Height > 558 || this.taskPane.Width > 718)
        {
            this.taskPane.Height = 558;
            this.taskPane.Width = 718;
        }
        else{
            this.taskPane.Width = 718;
            this.taskPane.Height = 558;
        }
    }        

I find a Solution for this One :

void NormalizeSize(object sender, EventArgs e)
    {
        if (this.taskPane.Height > 558 || this.taskPane.Width > 718)
        {
            this.taskPane.Height = 558;
            this.taskPane.Width = 718;
        }
        else{
            this.taskPane.Width = 718;
            this.taskPane.Height = 558;
        }
    }        
醉城メ夜风 2024-11-14 10:22:49

对于“不得关闭”问题的一部分,您可以使用这个而不是计时器:

private void myCustomTaskPane_VisibleChanged(object sender, EventArgs e)
{
  if (!myCustomTaskPane.Visible)
  {
    //Start new thread to make the CTP visible again since changing the
    //visibility directly in this event handler is prohibited by Excel.
    new Thread(() =>
    {
      myCustomTaskPane.Visible = true;
    }).Start();
  }
}

希望它有帮助,
约尔格

For the "Must not be closed"-Part of the problem you can maybe use this one instead of a timer:

private void myCustomTaskPane_VisibleChanged(object sender, EventArgs e)
{
  if (!myCustomTaskPane.Visible)
  {
    //Start new thread to make the CTP visible again since changing the
    //visibility directly in this event handler is prohibited by Excel.
    new Thread(() =>
    {
      myCustomTaskPane.Visible = true;
    }).Start();
  }
}

Hope it helps,
Jörg

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文