【问题标题】:How to create smooth rounded form in vb .NET如何在 vb .NET 中创建平滑的圆角形式
【发布时间】:2021-08-09 16:29:38
【问题描述】:

如何在 vb .net 中创建平滑的圆角形式
我不知道我该怎么做。

在上图中,这已经完成了,但是正如你所看到的,它是像素化的。

【问题讨论】:

标签: vb.net


【解决方案1】:

试试这个,更平滑的角落

  Private borderForm As New Form

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    With Me
        .FormBorderStyle = Windows.Forms.FormBorderStyle.None
        .Region = New Region(RoundedRectangle(.ClientRectangle, 50))
    End With
    With borderForm
        .ShowInTaskbar = False
        .FormBorderStyle = Windows.Forms.FormBorderStyle.None
        .StartPosition = FormStartPosition.Manual
        .BackColor = Color.Black
        .Opacity = 0.25
        Dim r As Rectangle = Me.Bounds
        r.Inflate(2, 2)
        .Bounds = r
        .Region = New Region(RoundedRectangle(.ClientRectangle, 50))
        r = New Rectangle(3, 3, Me.Width - 4, Me.Height - 4)
        .Region.Exclude(RoundedRectangle(r, 48))
        .Show(Me)
    End With


End Sub
Private Function RoundedRectangle(rect As RectangleF, diam As Single) As Drawing2D.GraphicsPath
    Dim path As New Drawing2D.GraphicsPath
    path.AddArc(rect.Left, rect.Top, diam, diam, 180, 90)
    path.AddArc(rect.Right - diam, rect.Top, diam, diam, 270, 90)
    path.AddArc(rect.Right - diam, rect.Bottom - diam, diam, diam, 0, 90)
    path.AddArc(rect.Left, rect.Bottom - diam, diam, diam, 90, 90)
    path.CloseFigure()
    Return path
End Function

Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
    Dim r As New Rectangle(1, 1, Me.Width - 2, Me.Height - 2)
    Dim path As Drawing2D.GraphicsPath = RoundedRectangle(r, 48)
    Using pn As New Pen(Color.Black, 2)
        e.Graphics.DrawPath(pn, path)
    End Using
End Sub

 

【讨论】:

  • 是的,完全一样,但不幸的是角落仍然像素化。
  • @vahidAraghi 我更新了答案。这看起来更好
  • @dr.null 亲爱的 dr.null 我希望角落平滑,而不是像素化。
  • @Bassies 亲爱的 Bassies,感谢您的帮助,但不幸的是,角落仍然像素化。
猜你喜欢
  • 2019-03-08
  • 1970-01-01
  • 1970-01-01
  • 2021-11-17
  • 2016-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多