Usr
Usr

Reputation: 59

Draw circle over my form with VB.Net

how can i draw circle all over my form?

what i have tried:

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

Upvotes: 0

Views: 8814

Answers (2)

KekuSemau
KekuSemau

Reputation: 6852

Okay, here's that with a circle ;-)

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

Upvotes: 1

user1693593
user1693593

Reputation:

Override the OnPaint event handler and do it from there, 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

Upvotes: 1

Related Questions