Progress Bars With A Gradient

Progress Bars With A Gradient

The tip “Color Status Indicator” [“101 Tech Tips for VB Developers,” Supplement to the February 1997 issue of VBPJ, page 26] got me thinking that it would look even more attractive to have the status change color in gradient steps. Instead of changing the color at particular points, start at red, blend to orange, then yellow, and finally green.

To try this, place a Sheridan 3-D panel on your form and set the FloodType property to 1 (Left to Right) and ShowFloodPct to False. Place a command button and a text box (set the Caption to blank) on the form to do your testing. Place this code in the form:

 Private Sub Command1_Click()	Dim i As Integer, iIncrement As Integer	Dim iMidPoint As Integer, iCheckpoint As Integer	Dim j As Integer, sAddIncrement As String	Dim sSubIncrement As String	iIterations = Val(Text1)	iMidPoint = iIterations * 0.5 - 1	' find the midpoint	If iIterations / 510 = iIterations  510 Then		'perfect algorithm		iIncrement = 1		iCheckpoint = 1	ElseIf iIterations < 510 Then		'increment the color faster		iIncrement = 510  iIterations		iCheckpoint = 1	Else		'change the color less frequently		iIncrement = 1		iCheckpoint = iIterations  510 + 1	End If	sAddIncrement = "&H0000" & _		Format$(iIncrement, "00") & "00"	sSubIncrement = "&H0000" & _		Format$(iIncrement, "0000")	SSPanel1.FloodColor = &HFF	'start the panel at Red	'At your preference show the 	'percentage. However, the tighter 	'the loop, the less valuable this is.	SSPanel1.FloodShowPct = True	For i = 0 To iIterations - 1		'do your real processing here		If i / iCheckpoint = i  iCheckpoint Then			With SSPanel1				If i <= iMidPoint Then					.FloodColor = _						.FloodColor + sAddIncrement				Else					.FloodColor = _						.FloodColor - sSubIncrement				End If				.FloodPercent = (i + 1) / iIterations * 100			End With		End If		'if the loop is tight, be sure to 		'release the processor 		'occasionally - also, some flood		'controls (other than SSPanel) 		'may require this to get the 		'color updated in the control		DoEvents	Next	MsgBox "All done!", vbOKOnly + vbInformation	SSPanel1.FloodPercent = 0	SSPanel1.FloodShowPct = FalseEnd Sub

The effect works best when your video is set to at least 16-bit (High Color). Because there are exactly 510 progressive gradients between red and green, the number of iterations you enter will influence what shade of green you end up with. As the iterations increase (>900), you'll end up with bright green.

See also  Monetize TikTok For Your Business

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist