I had defined the border style to none to making a Borderless Form, with an override method to customized title bar.
But when I put a panel control in design mode, it will cover my customized title bar, or put a statusStrip control under the Form, also cover outside border line which were customization by the form.
I set panel's top/left/width value to limit prevent exceeding the window, but it is not a good solution, because I also want to using Control.Dock Property to let it 'docked to its parent control'.
I had found another approach here: WPF borderless window resize with inner-margins ,but it can't.
Can I define 'margins' like CSS BOX, let the all new controls add to Form1 in design mode, then automatic to range of restrictions?
This my code to build a borderless form:
----
Test.cs
----
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace TestForm
{
public partial class Test : Form
{
protected override void WndProc(ref Message m)
{
....
base.WndProc(ref m);
}
private const int cGrip = 20; // Grip size
private const int cCaption = 35; // Caption bar height;
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x84)
{
Point pos = new Point(m.LParam.ToInt32());
pos = this.PointToClient(pos);
if (pos.Y < cCaption)
{
m.Result = (IntPtr)2;
return;
}
if (pos.X >= this.ClientSize.Width - cGrip && pos.Y >= this.ClientSize.Height - cGrip)
{
m.Result = (IntPtr)17;
return;
}
}
base.WndProc(ref m);
}
protected override void OnLoad(EventArgs e)
{
FormBorderStyle = FormBorderStyle.None;
base.OnLoad(e);
}
protected override void OnPaint(PaintEventArgs e)
{
Rectangle borderRectangle = this.ClientRectangle;
borderRectangle.Inflate(0, 0);
ControlPaint.DrawBorder3D(e.Graphics, borderRectangle, Border3DStyle.Raised);
base.OnPaint(e);
}
}
}
And Form1.cs:
namespace TestForm
{
public partial class Form1 : Test
{
public Form1()
{
//
}
}
}
- .Net Framework 4.0
- WinForms
Chinese Notes:
一旦在這個視窗放進一個 panel control,然後將其設置為「停駐於父容器中」,會造成原先的標題列效果被覆蓋; 亦或是放進一個 statusStrip control 在下方,也會造成下方版面的原本特製化視窗下方外框線被蓋住。
是否可以讓這個 From 可以直接在設計階段時,就可以讓所有被拖拉進來的 Controls 都限縮在一個特定範圍內?