Ste*_*Ste 1 .net c# visual-studio winforms
我有一个没有边框的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
);
Run Code Online (Sandbox Code Playgroud)
我需要一个无边界的表单,但是我想添加一个1px的边界。
在Paint表单的事件处理程序中,添加以下代码:
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(0, 0, Width - 1, Height - 1));
}
Run Code Online (Sandbox Code Playgroud)
祝好运!
| 归档时间: |
|
| 查看次数: |
2762 次 |
| 最近记录: |