c# - C# 设计模式内带有边距设置的无边框表单
问题描述
我已将边框样式定义为 none 以制作无边框表单,并使用覆盖方法来自定义标题栏。
但是当我在设计模式下放置一个面板控件时,它会覆盖我自定义的标题栏,或者在表单下放置一个statusStrip控件,也会覆盖表单自定义的外部边框线。
我将面板的顶部/左侧/宽度值设置为限制防止超出窗口,但这不是一个好的解决方案,因为我还想使用 Control.Dock 属性让它“停靠到其父控件”。
我在这里找到了另一种方法: WPF borderless window resize with inner-margins,但它不能。
我可以像 CSS BOX 一样定义“边距”,让所有新控件在设计模式下添加到 Form1,然后自动限制范围吗?
这是我构建无边界表单的代码:
----
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);
}
}
}
和 Form1.cs:
namespace TestForm
{
public partial class Form1 : Test
{
public Form1()
{
//
}
}
}
- .Net 框架 4.0
- WinForms
中文注释:
在视听范围内被视听小组控制,造成其“停职,会造成这个安排的父中的标题”,然后将每个人的状态,的原本特制化视窗外框线被盖住。</p>
是否可以让这个从可以直接在设计阶段时,就可以让所有被拖拉进来的 Controls 都限制在一个特定范围内?</p>
解决方案
推荐阅读
- netsuite - 如何从 SuiteScript 2.0 Suitelet 中检索值以进行 POST?
- c# - LINQ2SQL 表达式 - 转换日期时转换失败
- c# - DependencyObject 不能很好地处理对象属性的相等性
- fortran - Fortran 不对数组或程序变量调用 FINAL
- php - 如何将按钮文本从阅读更多更改为帖子类别和 wordpress 中的其他文本?
- java - Java 11 升级缺少 javax.annotation.security
- excel - VBA Excel 宏 - 显示与列相关的单元格值
- javascript - 具有页面对象模型的量角器(打字稿错误)
- sql - 如何使用按网格中的单元格分组的 SQL 进行计数?
- python - 了解生成器内部的 StopIteration 处理非平凡情况