Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2010 如何禁用自定义任务窗格的调整大小和关闭按钮?_Visual Studio 2010_C# 4.0_Ms Office_Vsto - Fatal编程技术网

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

Visual studio 2010 如何禁用自定义任务窗格的调整大小和关闭按钮?,visual-studio-2010,c#-4.0,ms-office,vsto,Visual Studio 2010,C# 4.0,Ms Office,Vsto,如何防止Office自定义任务窗格调整大小,使其仅具有且始终具有维度,而不能使用“关闭”按钮关闭 至于调整大小,只需监视任务窗格的调整大小事件并重置大小。但是你可能会考虑+为什么你会想这么做。如果有任务窗格所需的最小大小,那么限制最小大小可能更有意义。如果内容是可调整大小的,也许它们应该是 您还可以重写OnLayout方法。这通常会更好 对于Close按钮,我认为您应该拦截“VisibleChanged”事件,并使窗格在被隐藏时可见。我记得,任务窗格本身并不是“关闭”的,只是设置为不可见。我找到

如何防止Office自定义任务窗格调整大小,使其仅具有且始终具有维度,而不能使用“关闭”按钮关闭


至于调整大小,只需监视任务窗格的调整大小事件并重置大小。但是你可能会考虑+为什么你会想这么做。如果有任务窗格所需的最小大小,那么限制最小大小可能更有意义。如果内容是可调整大小的,也许它们应该是

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


对于Close按钮,我认为您应该拦截“VisibleChanged”事件,并使窗格在被隐藏时可见。我记得,任务窗格本身并不是“关闭”的,只是设置为不可见。

我找到了一个解决方案:

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

其中_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的引用,这是问题的一部分,您可以使用此命令而不是计时器:

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();
  }
}
希望有帮助,
Jörg

如果您正在设置宽度和高度,我假设您没有停靠任务窗格。那么,为什么不简单地使用一个弹出式表单呢?@Mathias在这个项目中,我应该使用一个自定义任务窗格!如果你接到命令马上发货,这没关系。然而,这不是一个可行的长期解决办法。像这样的黑客会导致维护噩梦(其他开发人员不会期望解决方案是这样的,而且它不是很直观)和代码脆性(微小的更改可能会产生涟漪效应)。我必须同意phil的观点,这些神奇的数字让我害怕。为什么是718和558?如果窗格大小以某种方式基于其内容,则最好直接引用内容,即将任务窗格的宽度和高度基于其中一个控件的右下角位置。如果可以,我会将此取消标记为SO答案。@drventure关于调整事件大小的回答要好得多,甚至Mathias和docking的评论都是Orhadox编码解决方案。十年后,我希望能在电视上看到完整版本DailyWTF@thompson好吧,这似乎更像是一个个人黑客而不是一个解决方案!谢谢我现在正在处理这个问题,在拦截事件时不能更改Visible的值。这可能是一个需要计时的东西。@drventure谢谢你的回答!这真的比我的更可行!事实上,我的解决方案更个人化!
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();
  }
}