【问题标题】:Draw circle over my form with VB.Net用 VB.Net 在我的表单上画圈
【发布时间】:2012-10-22 15:20:04
【问题描述】:

如何在我的表单上画圆?

我尝试过的:

Dim bmp As New Bitmap(Me.Width, Me.Height)
cWidth = 3
Me.BackgroundImage = Circle (Me.Width, Me.Height,bmp,cWidth)

【问题讨论】:

    标签: .net vb.net winforms


    【解决方案1】:

    覆盖 OnPaint 事件处理程序并从那里执行,f.ex:

    Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)
    
        Dim myPen As New Pen(Color.Red, 3) 'to set width of pen
    
        e.Graphics.DrawEllipse(myPen, 0, 0, _
                               Me.ClientSize.Width - 1, Me.ClientSize.Height - 1)
    
        myPen.Dispose()
    
    End Sub
    

    【讨论】:

    • 没问题。我没有实现笔宽补偿,但实现补偿很简单。
    【解决方案2】:

    好的,这是带有圆圈 ;-)

    Public Class Form1
        Private Sub Form1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
            Dim p As Pen
            Dim d As Integer
            Dim x As Integer
    
            d = Math.Min(Me.ClientRectangle.Width, Me.ClientRectangle.Height)
            x = Me.ClientRectangle.Width / 2 - d / 2
    
            p = New Pen(Brushes.Navy, 7)
            e.Graphics.DrawEllipse(p, New Rectangle(x, 0, d, d))
        End Sub
    
        Private Sub Form1_Resize(sender As System.Object, e As System.EventArgs) Handles MyBase.Resize
            Me.Invalidate()
        End Sub
    End Class
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      相关资源
      最近更新 更多