Sinisterly
[Source Release] [VB.Net] DrawProgress Function - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework)
+--- Thread: [Source Release] [VB.Net] DrawProgress Function (/Thread-Source-Release-VB-Net-DrawProgress-Function)



[Source Release] [VB.Net] DrawProgress Function - Coder-san - 02-19-2011

DrawProgress Function - DrawProgress on almost Any control!

Hello people. Smile
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. Smile
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 Sub

Usage:
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. Smile


RE: [Source Release] [VB.Net] DrawProgress Function - 1234hotmaster - 02-19-2011

omg this shows all RGB betwen the 3 colors :O

excellent project indeed Biggrin


RE: [Source Release] [VB.Net] DrawProgress Function - Coder-san - 05-16-2011

ProgressBar updated. Smile


RE: [Source Release] [VB.Net] DrawProgress Function - nosferatus - 05-18-2011

Like always, your work is amazing.
Regards.