【问题标题】:Why is the circle I drew larger than expected?为什么我画的圆圈比预期的大?
【发布时间】:2018-09-07 03:25:05
【问题描述】:

我用 Graphics 画了一个椭圆/圆。当我在 WYSIWYG 编辑器中时,它是正确的尺寸。但是,当我运行程序时,圆圈变大了。

correct sized circle in editor

too large sized circle

“太大的圆”也具有较低的分辨率和锯齿状边缘。

我如何使它的大小相同?

    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)

【问题讨论】:

  • 尝试设置Me.ClientSize = New Size(heightWidth, heightWidth)
  • ClientSize 不起作用
  • 你看过heightWidth的值了吗?两个版本都一样吗?

标签: vb.net drawellipse


【解决方案1】:

“过大的圆”也具有较低的分辨率并且具有锯齿状边缘。

    pEvent.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality

【讨论】:

    【解决方案2】:

    在绘制事件中设置表单的大小是一个很大的禁忌。在设计器中将表单的尺寸设置为不具有大小的表单边框,或者将表单的 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-03
      • 2021-05-01
      相关资源
      最近更新 更多