If _BackBuffer Is Nothing Then
_BackBuffer = New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
End If
Dim x As Integer
Dim y As Integer
Dim rect As Rectangle
Dim cnt As Integer = 0
Dim g As Graphics = Graphics.FromImage(_BackBuffer)
Dim p As Pen = Nothing
Dim b As LinearGradientBrush = Nothing
Dim mAv As Integer 'is the actual value taking in consideration the number of led lights compared to the maximum
Dim Hav As Integer 'is the most recent High Value it hovers for a few seconds then fades until another value is greater
g.Clear(Color.White)
g.SmoothingMode = SmoothingMode.AntiAlias
Dim c1 As Color
Dim c2 As Color
If _Orientation = Windows.Forms.Orientation.Vertical Then
x = 0
y = Me.Height - H - 1
Else
x = 0
y = 0
End If
mAv = CInt((AV * _Value) / _Max)
Hav = CInt((AV * _HighValue) / _Max)
Do Until cnt >= AV
rect = New Rectangle(x, y, W, H)
If cnt <= AV / 2 Then
If cnt <= mAv AndAlso cnt <> Hav Then
b = New LinearGradientBrush(rect, Color.LightGreen, Color.LightGreen, LinearGradientMode.Vertical)
p = New Pen(Color.Green, 1)
ElseIf cnt > mAv AndAlso cnt <> Hav Then
c1 = ColorChanger.SetBrightness(Color.Green, 0.1)
c1 = ColorChanger.SetSaturation(c1, 0.2)
c2 = ColorChanger.SetBrightness(Color.Green, 0.2)
c2 = ColorChanger.SetSaturation(c2, 0.3)
b = New LinearGradientBrush(rect, c1, c2, LinearGradientMode.Vertical)
p = New Pen(c1, 1)
ElseIf cnt = Hav Then
b = New LinearGradientBrush(rect, Color.LightBlue, Color.LightBlue, LinearGradientMode.Vertical)
p = New Pen(Color.DarkBlue)
End If
ElseIf cnt > AV / 2 And cnt <= (AV / 4) * 3 Then
If cnt <= mAv AndAlso cnt <> Hav Then
b = New LinearGradientBrush(rect, ColorChanger.ModifyBrightness(Color.Yellow, 1.3), ColorChanger.ModifyBrightness(Color.Yellow, 1.3), LinearGradientMode.Vertical)
p = New Pen(ColorChanger.ModifyBrightness(Color.Yellow, 0.5), 1)
ElseIf cnt > mAv AndAlso cnt <> Hav Then
c1 = ColorChanger.SetBrightness(Color.Yellow, 0.3)
c1 = ColorChanger.SetSaturation(c1, 0.4)
c2 = ColorChanger.SetBrightness(Color.Yellow, 0.4)
c2 = ColorChanger.SetSaturation(c2, 0.5)
b = New LinearGradientBrush(rect, c1, c2, LinearGradientMode.Vertical)
p = New Pen(c1, 1)
ElseIf cnt = Hav Then
b = New LinearGradientBrush(rect, Color.LightBlue, Color.LightBlue, LinearGradientMode.Vertical)
p = New Pen(Color.DarkBlue)
End If
ElseIf cnt > (AV / 4) * 3 Then
If cnt <= mAv AndAlso cnt <> Hav Then
b = New LinearGradientBrush(rect, Color.Red, Color.Red, LinearGradientMode.Vertical)
p = New Pen(ColorChanger.ModifyBrightness(Color.DarkRed, 0.2), 1)
ElseIf cnt > mAv AndAlso cnt <> Hav Then
c1 = ColorChanger.SetBrightness(Color.DarkRed, 0.3)
c1 = ColorChanger.SetSaturation(c1, 0.4)
c2 = ColorChanger.SetBrightness(Color.DarkRed, 0.4)
c2 = ColorChanger.SetSaturation(c2, 0.5)
p = New Pen(c1, 1)
b = New LinearGradientBrush(rect, c1, c2, LinearGradientMode.Vertical)
ElseIf cnt = Hav Then
b = New LinearGradientBrush(rect, Color.LightBlue, Color.LightBlue, LinearGradientMode.Vertical)
p = New Pen(Color.LightBlue)
End If
End If
g.FillRectangle(b, rect)
g.DrawRectangle(p, rect)
If _Orientation = Windows.Forms.Orientation.Vertical Then
y -= H
ElseIf _Orientation = Windows.Forms.Orientation.Horizontal Then
x += W
End If
cnt += 1
rect = Nothing
p.Dispose()
b.Dispose()
Loop
g.Dispose()
e.DrawImageUnscaled(_BackBuffer, 0, 0)
e.Dispose() 'originally I didn't dispose of this manually. But I added it, and still got the error