【发布时间】:2020-12-07 13:20:01
【问题描述】:
我有一个 Windows 窗体应用程序,它应该是无边界的(即使没有标题栏)并且可以调整大小和移动。
到目前为止,我已将 BorderStyle 设置为“无”,这会删除所有边框,让我的程序看起来很漂亮。
现在我添加了以下内容的隐形边框:
private const int cGrip = 16; // Grip size
private const int cCaption = 50; // Caption bar height;
protected override void OnPaint(PaintEventArgs e)
{
Rectangle rc = new Rectangle(this.ClientSize.Width - cGrip, this.ClientSize.Height - cGrip, cGrip, cGrip);
ControlPaint.DrawSizeGrip(e.Graphics, this.BackColor, rc);
rc = new Rectangle(0, 0, this.ClientSize.Width, cCaption);
//e.Graphics.FillRectangle(Brushes.DarkBlue, rc);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x84)
{ // Trap WM_NCHITTEST
Point pos = new Point(m.LParam.ToInt32());
pos = this.PointToClient(pos);
if (pos.Y < cCaption)
{
m.Result = (IntPtr)2; // HTCAPTION
return;
}
if (pos.X >= this.ClientSize.Width - cGrip && pos.Y >= this.ClientSize.Height - cGrip)
{
m.Result = (IntPtr)17; // HTBOTTOMRIGHT
return;
}
}
base.WndProc(ref m);
}
蓝色矩形通过 OnPaint() 方法呈现,并显示用户可以在按住鼠标左键时移动窗口的字段。
我的问题是,这个矩形在我的标签下方。 有谁知道如何获取标签前面的矩形?
另一种方法是禁用变成深灰色的标签。 如果我可以更改禁用标签的颜色,您将解决我的问题。
【问题讨论】:
-
标签的
BackColor是什么?您可能应该尝试改写您对问题的描述。我也不确定我是否理解 -
看起来很眼熟,这里需要注明出处。不要使用标签,在 OnPaint() 中使用 TextRenderer.DrawText()。
-
感谢您的建议,即使不是所有人都明白我问了什么@41686d6564