【问题标题】:How To Hide TitleBar in Visual Studio Extensibility Package如何在 Visual Studio 扩展包中隐藏 TitleBar
【发布时间】:2016-02-24 09:17:21
【问题描述】:

我正在创建一个 Visual Studio 扩展包。我正在尝试创建一个没有标题栏的 ToolWindow。 我不希望最小化、最大化或关闭按钮可用。我想通过按钮处理关闭等功能 在我的用户控制范围内。如果可能的话,有人可以告诉我吗?

【问题讨论】:

    标签: visual-studio-2015 vs-extensibility


    【解决方案1】:

    编辑:这适用于标准 Windows 窗体。理论上应该和 VS 可扩展性一样。。我会去检查自己,但我目前没有安装可扩展性工具。

    要完全隐藏框架,您可以单击表单,转到表单选项,然后设置FormBorderStyle = None。从这里,您可以在自己的表单上设计一个替换栏。

    只是一个警告:一旦你这样做,你会发现你不能在屏幕上移动你的窗口。要解决此问题,请将此代码应用于替换标题栏的任何控件...

    命名空间声明:

    Using System.Drawing;

    全局变量:

    //Declare the variables that allow you to drag the form
    private bool dragging;
    private Point dragAt = Point.Empty;
    

    方法

    //This method is called when you have locked onto a control so you can drag the form around
    public void Pick(Control control, int x, int y)
    {
        dragging = true;
        dragAt = new Point(x, y);
        control.Capture = true;
    }
    
    //This method is called when you release the control
    public void Drop(Control control)
    {
        dragging = false;
        control.Capture = false;
    }
    

    控件处理程序——这些处理程序用于您用来保存新工具栏的任何控件。或者,您可以创建这些通用处理程序(而不是 ObjectName_WhatItHandles,您可以将它们命名为 WhatItHandlesHandler)并将它们分配给触发 MouseDownMouseUpMouseMove 事件的任何控件。

    //This method is called whenever the mouse button is held down
    private void TableLayoutPanel1_MouseDown(object sender, MouseEventArgs e)
    {
        Pick((Control)sender, e.X, e.Y);
    }
    
    //This method is called whenever the mouse button is released
    private void TableLayoutPanel1_MouseUp(object sender, MouseEventArgs e)
    {
        Drop((Control)sender);
    }
    
    //This method is called when you move the mouse around
    private void TableLayoutPanel1_MouseMove(object sender, MouseEventArgs e)
    {
        if (dragging)
        {
            Left = e.X + Left - dragAt.X;
            Top = e.Y + Top - dragAt.Y;
        }
        else dragAt = new Point(e.X, e.Y);
    }
    

    【讨论】:

      猜你喜欢
      • 2014-09-02
      • 2018-01-27
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      • 2014-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多