Imports System.Drawing.Drawing2D
Public Class Form1
Private Sub
Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Me.CenterToParent()
Me.SetStyle(ControlStyles.ResizeRedraw,
True)
Me.SetStyle(ControlStyles.DoubleBuffer,
True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint,
True)
End Sub
Private Sub
Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Static i As Integer
i +=
1
If i = 360 Then
i
= 0
End If
Me.BackgroundImage = DrawProgressBar(e.Graphics, i)
End Sub
Private Function
DrawProgressBar(ByVal g As Graphics, ByVal angle As Integer) As Bitmap
Dim bmp As New Bitmap(Me.ClientRectangle.Width, Me.ClientRectangle.Height)
g = Graphics.FromImage(bmp)
Dim percent As Double
percent = Math.Round(angle * 100 /
360, 1)
Dim gp As New GraphicsPath
Dim rect As Rectangle = New Rectangle(0, 0, bmp.Width, bmp.Height)
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
g.DrawString(percent & " %",
New Font("Arial", 20, FontStyle.Regular),
Brushes.Black, New
Point(rect.Width / 2, rect.Height / 2), sf)
g.DrawEllipse(Pens.Black, rect)
gp.AddPie(rect, 180, angle)
Dim holeRect As Rectangle = New Rectangle(rect.X + 15, rect.Y + 15, rect.Width -
30, rect.Height - 30)
g.DrawEllipse(Pens.Black, holeRect)
g.Clip = (New Region(gp))
gp.AddPie(holeRect, 180, angle)
Dim gb As New LinearGradientBrush(rect,
Color.Red, Color.Blue,
45)
g.FillPath(gb, gp)
Invalidate(rect)
Return bmp
End Function
End Class
0 comentários:
Postar um comentário