[英].NET C# - WinForm border
我有一个没有边框的WinForm(无边界)。 如何在表单中添加1px黑色边框?
public MainForm()
{
InitializeComponent();
this.DoubleBuffered = true;
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 10, 10)); // adjust these parameters to get the lookyou want.
}
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect, // x-coordinate of upper-left corner
int nTopRect, // y-coordinate of upper-left corner
int nRightRect, // x-coordinate of lower-right corner
int nBottomRect, // y-coordinate of lower-right corner
int nWidthEllipse, // height of ellipse
int nHeightEllipse // width of ellipse
);
我需要一个无边界的表单,但是我想添加一个1px的边界。
在窗体的Paint
事件处理程序中,添加以下代码:
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(0, 0, Width - 1, Height - 1));
}
祝好运!
您可以添加一个完全停靠的Panel
,以及另一个完全停靠的Panel
作为子控件。 设定外的填充Panel
1和外部的背景色Panel
为黑色。
然后将内部Panel
的背景色设置为SystemColors.Control
。
如果你不想画画
将4个宽度或高度2或4的面板和黑色背景色分别固定在顶部,右侧,底部和左侧的4个侧面后,分别添加
this.FormBorderStyle = FormBorderStyle.None;
Panel pnlTop = new Panel() { Height = 4, Dock = DockStyle.Top, BackColor = Color.Green };
this.Controls.Add(pnlTop);
Panel pnlRight = new Panel() { Width = 4, Dock = DockStyle.Right, BackColor = Color.Green };
this.Controls.Add(pnlRight);
Panel pnlBottom = new Panel() { Height = 4, Dock = DockStyle.Bottom, BackColor = Color.Green };
this.Controls.Add(pnlBottom);
Panel pnlLeft = new Panel() { Width = 4, Dock = DockStyle.Left, BackColor = Color.Green };
this.Controls.Add(pnlLeft);
您还可以更改其鼠标指针以调整图标的大小,也可以调整表单的大小,以编写有关鼠标事件的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.