[Source Release] [VB.Net] DrawProgress Function 02-19-2011, 02:51 PM
#1
DrawProgress Function - DrawProgress on almost Any control!
Hello people.
I've made a similar function in Visual Basic 6 before, which is quite handy at times.
Now I present to you a VB.Net version of it, it is based on a DrawGradient function, coded by Michael H from developerFusion
Update
[altimg=http://i.imgur.com/Yfb58.png]DrawProgress Function by Coder-san[/altimg]
I needed a custom ProgressBar in a new link visitor app, so I updated it.
Usage:
Note:
Have a great day.
Hello people.

I've made a similar function in Visual Basic 6 before, which is quite handy at times.
Now I present to you a VB.Net version of it, it is based on a DrawGradient function, coded by Michael H from developerFusion
Update
[altimg=http://i.imgur.com/Yfb58.png]DrawProgress Function by Coder-san[/altimg]
I needed a custom ProgressBar in a new link visitor app, so I updated it.

Code:
Public Sub DownloadProgress(ByVal aControl As ToolStripStatusLabel, ByVal Value As Integer, ByVal Max As Integer, _
ByVal Color1 As Color, ByVal Color2 As Color, ByVal Color3 As Color, ByVal Color4 As Color, _
Optional ByVal mode As System.Drawing.Drawing2D.LinearGradientMode = Drawing2D.LinearGradientMode.Vertical)
Dim bmp As New Bitmap(aControl.Width, aControl.Height)
Dim widthVal As Integer = CInt((aControl.Width / Max) * Value)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim Rect1 As New RectangleF(0, 0, widthVal, aControl.Height)
Dim Rect2 As New RectangleF(widthVal, 0, aControl.Width, aControl.Height)
Dim lineGBrush2 As New System.Drawing.Drawing2D.LinearGradientBrush(Rect2, Color3, Color4, mode)
g.FillRectangle(lineGBrush2, New RectangleF(0, 0, aControl.Width, aControl.Height))
g.DrawRectangle(Pens.White, New Rectangle(1, 1, aControl.Width - 3, aControl.Height - 3))
If Value > 0 Then
Dim lineGBrush As New System.Drawing.Drawing2D.LinearGradientBrush(Rect1, Color.FromArgb(200, Color1), Color.FromArgb(200, Color2), mode)
g.FillRectangle(lineGBrush, New RectangleF(0, 0, widthVal, aControl.Height))
lineGBrush = New System.Drawing.Drawing2D.LinearGradientBrush(Rect1, Color.FromArgb(Color2.R, Color2.G - 100, Color2.B), Color.FromArgb(Color1.R - 80, Color1.G - 80, Color1.B), mode)
g.FillRectangle(lineGBrush, New RectangleF(0, aControl.Height / 2, widthVal, aControl.Height / 2))
lineGBrush = New System.Drawing.Drawing2D.LinearGradientBrush(Rect1, Color.FromArgb(100, Color2), Color.FromArgb(100, Color1), Drawing2D.LinearGradientMode.Horizontal)
g.FillRectangle(lineGBrush, New RectangleF(0, 0, widthVal, aControl.Height))
g.DrawRectangle(New Pen(New SolidBrush(Color.FromArgb(100, Color1.R - 120, Color1.G - 80, Color1.B - 40))), New Rectangle(1, 1, widthVal - 2, aControl.Height - 3))
End If
g.DrawRectangle(Pens.DarkGray, New Rectangle(0, 0, aControl.Width - 1, aControl.Height - 1))
bmp.SetPixel(0, 0, Color.Transparent)
bmp.SetPixel(0, bmp.Height - 1, Color.Transparent)
bmp.SetPixel(bmp.Width - 1, 0, Color.Transparent)
bmp.SetPixel(bmp.Width - 1, bmp.Height - 1, Color.Transparent)
aControl.BackgroundImage = bmp
g.Dispose()
End SubUsage:
Code:
DownloadProgress(ToolStripStatusLabel1, trkBar.Value, trkBar.Maximum, Color.Aquamarine, Color.CadetBlue, Color.AliceBlue, Color.LightGray)Note:
- To change colour, simply change Color3, and keep everything the same unless you feel artistic.
- RGB values are increased and decreased in the Function, so it cannot work with every colour (colors may cross the limit of 0-255).
- Currently tested and worked with LawnGreen and CadetBlue.
Have a great day.
![[Image: rytwG00.png]](http://i.imgur.com/rytwG00.png)
Redcat Revolution!





![[+]](https://sinister.li/images/modern/collapse_collapsed.png)