我用图形画了一个椭圆/圆圈。当我在Wysiwyg编辑中时,这是正确的大小。但是,当我运行程序时,圆圈更大。
编辑器中正确的圆圈
太大尺寸的圆
"太大尺寸的圆"也具有较低的分辨率,并且边缘锯齿状。
我如何使其大小相同?
Protected Overrides Sub OnPaint(
ByVal pEvent _
As PaintEventArgs)
Me.Size = New Size(heightWidth, heightWidth)
'MyBase.OnPaint(pEvent)
Dim CenterCircle _
As New Rectangle(0, 0, heightWidth, heightWidth)
Dim colorBigCircle As Color = Color.FromArgb(218, 227, 243)
Dim colorSmallCircle As Color = Color.FromArgb(67, 99, 155)
pEvent.Graphics.FillEllipse(
New SolidBrush(
colorBigCircle
),
CenterCircle)
pEvent.Graphics.DrawEllipse(
New Pen(
colorSmallCircle, 3
),
CenterCircle)
"太大尺寸的圆"也具有较低的分辨率,并且边缘锯齿状。
pEvent.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
在油漆事件中设置表单的大小是一个很大的禁忌。要么将表单的尺寸设置在设计器中的尺寸,并具有不大范围的表单边框,要么将表单的最小尺寸和最大尺寸设置为相同的尺寸。
您应该处理图形对象。设置SmootleingMode将修复圆圈的锯齿状边缘。您的油漆代码应该看起来像这样:
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
Dim centerCircle As New Rectangle(0, 0, Me.ClientSize.Width, Me.ClientSize.Height)
Dim colorBigCircle As Color = Color.FromArgb(218, 227, 243)
Dim colorSmallCircle As Color = Color.FromArgb(67, 99, 155)
Using br As New SolidBrush(colorBigCircle)
e.Graphics.FillEllipse(br, centerCircle)
End Using
Using p As New Pen(colorSmallCircle, 3) With {.Alignment = PenAlignment.Inset}
e.Graphics.DrawEllipse(p, centerCircle)
End Using
End Sub