我用Graphics绘制了一个椭圆/圆。当我在WYSIWYG编辑器中时它是正确的大小。但是,当我运行程序时,圆圈更大。
correct sized circle in editor
"太大的圆圈"也是分辨率较低,边缘锯齿状。
如何使其尺寸相同?
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)
答案 0 :(得分:0)
“太大的圆圈”也具有较低的分辨率并且具有锯齿状边缘。
pEvent.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
答案 1 :(得分:0)
在paint事件中设置表单的大小是一个很大的禁忌。在设计器中使用不可大小的表单边框设置表单的维度,或将表单的MinimumSize和MaximumSize设置为相同的维度。
你应该处理你的绘图对象。设置SmoothingMode将修复圆的锯齿状边缘。你的油漆代码应该是这样的:
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