[英].NET C# - WinForm border
I have a WinForm without a border (borderless). 我有一个没有边框的WinForm(无边界)。 How can I add a 1px black border to the form?
如何在表单中添加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
);
I need a borderless form but I want to add a 1px border. 我需要一个无边界的表单,但是我想添加一个1px的边界。
In the Paint
event handler of the form, add this code: 在窗体的
Paint
事件处理程序中,添加以下代码:
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(0, 0, Width - 1, Height - 1));
}
Good luck! 祝好运!
You could add a fully docked Panel
, and another fully docked Panel
as a child control. 您可以添加一个完全停靠的
Panel
,以及另一个完全停靠的Panel
作为子控件。 Set the padding of the outer Panel
to 1 and the background color of the outer Panel
to black. 设定外的填充
Panel
1和外部的背景色Panel
为黑色。
Then set the background color of the inner Panel
to SystemColors.Control
. 然后将内部
Panel
的背景色设置为SystemColors.Control
。
If you don't want to paint, 如果你不想画画
Add 4 panels width or height 2 or 4 and black background colour after dock them in 4 sides differently on top, right, bottom, left respectively 将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);
You can also change their mouse pointer to resize icons also you can resize the form writing some code on mouse events. 您还可以更改其鼠标指针以调整图标的大小,也可以调整表单的大小,以编写有关鼠标事件的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.