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.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a