Title | Use the Invalidate method to draw a centered circle whenever the user resizes a form in VB .NET |
Description | This example shows how to use the Invalidate method to draw a centered circle whenever the user resizes a form in VB .NET. |
Keywords | VB.NET, circle, center, resize, Paint, GDI+ |
Categories | VB.NET, Graphics |
|
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles _
MyBase.Paint
DrawCircle(e.Graphics)
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles MyBase.Resize
Me.Invalidate()
End Sub
Private Sub DrawCircle(ByVal gr As Graphics)
Const RADIUS As Integer = 20
Dim x As Integer = Me.ClientSize.Width \ 2 - RADIUS
Dim y As Integer = Me.ClientSize.Height \ 2 - RADIUS
gr.Clear(Me.BackColor)
gr.DrawArc(Pens.Blue, x, y, 2 * RADIUS, 2 * RADIUS, 0, _
360)
gr.DrawLine(Pens.Red, 0, 0, Me.ClientSize.Width, _
Me.ClientSize.Height)
gr.DrawLine(Pens.Red, 0, Me.ClientSize.Height, _
Me.ClientSize.Width, 0)
End Sub
|