c# - .NET C# - WinForm 边框

标签 c# .net winforms visual-studio

我有一个没有边框(borderless)的 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));
}

祝你好运!

关于c# - .NET C# - WinForm 边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5476892/

相关文章:

c# - 推送开始调试后 VS 2013 停止工作

c# - 我应该如何在 F# 项目中序列化来自 Refit 的 JSON?

.net - WCF生命周期事件

c# - 用于多个支付网关的最佳模式

winforms - 如何使用Powershell和WPF构建动态链接列表?

c# - 具有 C# 背景的编写 JavaScript 的常见错误

c# - 是否可以在 XP 上运行 .NET 4.5 应用程序?

c# - 如何编写自动缩放到系统字体和 dpi 设置的 WinForms 代码?

c# - 为什么 .NET 为我的应用程序保留这么多内存?

c# - 在azure中托管共享dll