如何在 vb .NET 中创建平滑的圆形
How to create smooth rounded form in vb .NET
如何在 vb .net
中创建平滑的圆角形式
我不知道该怎么做。
In the image above, this has been done, but as you can see, it is pixelated.
试试这个,更平滑的角
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
如何在 vb .net
中创建平滑的圆角形式
我不知道该怎么做。
In the image above, this has been done, but as you can see, it is pixelated.
试试这个,更平滑的角
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