我一直在研究改变Windows窗体边框的颜色,发现它是由Windows决定的,好吧,这是有道理的,所以我看到以前问过这个问题的人被告知去这里http://customerborderform.codeplex.com/ http://customerborderform.codeplex.com/该网站目前似乎无法使用。那么我必须自己制作框架吗?如果是这样,我该去哪里解决这个问题?我使用的是 Visual Studio 2012。
这是一个绘制自己边框的表单示例,可以调整大小和移动......:
public partial class BorderForm : Form
{
public BorderForm()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.ResizeRedraw, true);
BorderColor = Color.DarkSlateGray;
}
private const int hWidth = 12; // resize handle width
private const int bWidth = 28; // border width
public Color BorderColor { get; set; }
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
protected override void OnPaint(PaintEventArgs e)
{
// draw the border..
using (Pen pen = new Pen(BorderColor, bWidth)
{ Alignment = System.Drawing.Drawing2D.PenAlignment.Inset})
e.Graphics.DrawRectangle(pen, ClientRectangle);
// now maybe draw a title text..
base.OnPaint(e);
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x84) // Trap WM_NCHITTEST
{
Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16);
pos = PointToClient(pos);
bool isTop = pos.Y <= hWidth;
bool isBottom = pos.Y >= ClientSize.Height - hWidth;
bool isRight = pos.X >= ClientSize.Width - hWidth;
bool isLeft = pos.X <= hWidth;
m.Result = (IntPtr)1;
if (isTop) m.Result =
isLeft ? (IntPtr)13 : isRight ? (IntPtr)14 : (IntPtr)12;
else if (isBottom) m.Result =
isLeft ? (IntPtr)16 : isRight ? (IntPtr)17 : (IntPtr)15;
else if (isLeft) m.Result = (IntPtr)10;
else if (isRight) m.Result = (IntPtr)11;
if ( m.Result != (IntPtr)1) return;
}
base.WndProc(ref m);
}
}
The WM_NCHITTEST https://msdn.microsoft.com/en-us/library/windows/desktop/ms645618%28v=vs.85%29.aspx文档向您展示了如何模拟点击控件并调整框的大小(如果您需要的话)。当然,你也应该以某种方式画它们!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)