2011-09-20 127 views
48

如何删除窗体顶部的蓝色边框? (我不知道它的确切名字。)删除Windows窗体中的标题栏

+2

它被称为TitleBar,你可以隐藏它将表单的边框样式属性更改为无边框或无。 –

回答

103

您可以设置属性FormBorderStyle首屈一指的设计师, 或代码:

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 
+3

有一个错字。它是'FormBorderStyle':) – ty812

10

设置窗体的FormsBorderStyleNone

如果这样做,这取决于您如何实现窗口的拖动和关闭功能。

55

如果Blue Border thats on top of the Window Form你的意思是titlebar,制定表格ControlBox属性falseText属性为空字符串(“”)。

这里有一个片段:

this.ControlBox = false; 
this.Text = String.Empty; 
+6

你的解决方案比将边框样式设置为None更有优势,因为...它会使边框完整无缺:) +1 – Spook

+0

不知何故,如果通过“FormBorderStyle.None”执行操作,以某种方式在窗体上绘制(OnPaint在一个将Dock的'Dock'设置为'Fill'的picturebox中设置图像),直到我改变了FormBorderStyle.None的边框设置,但这样绘图仍然适用于我:) – DrCopyPaste

+0

@Spook:我打算去问一个新的线程:) – Jack

8
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None 
16

而且这段代码添加到您的形式,以使其可拖动依然。 https://jachman.wordpress.com/2006/06/08/enhanced-drag-and-move-winforms-without-having-a-titlebar/

我们摆脱标题栏:

构造函数(即调用的InitializeComponent()的方法


private const int WM_NCHITTEST = 0x84; 
private const int HTCLIENT = 0x1; 
private const int HTCAPTION = 0x2; 

/// 
/// Handling the window messages 
/// 
protected override void WndProc(ref Message message) 
{ 
    base.WndProc(ref message); 

    if (message.Msg == WM_NCHITTEST && (int)message.Result == HTCLIENT) 
     message.Result = (IntPtr)HTCAPTION; 
} 

该代码是前右只是将它加入但仍然有一个边界合并其他响应的代码:

this .ControlBox = false;

this.Text = String.Empty;

与此行:

this.FormBorderStyle = FormBorderStyle.FixedSingle;


把那些3行代码到窗体的onload事件,你应该有一个很好的“浮动”的形式可拖动与窄边框(使用FormBorderStyle.None如果你想无边框)。