Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing reflection of a progressbar control in winforms VB

Here is an image of what I am trying to achieve:

http://www.findmysoft.com/img/news/Windows-7-Beta-1-with-Updated-Boot-Screen-Drops-Next-Month.jpg

As you can see, there is a slight reflection under the progress bar.

I have a custom progress bar that is heavily based on this code:
http://www.codeproject.com/Articles/19309/Vista-Style-Progress-Bar-in-C

Note: My code is in VB.

Problem - I would like to draw a reflection of that progress bar under it so it looks similar to the image I have given above. I have been told that one way to do it is using pixels, which need to be done manually. Is that the only option? Is there any other/easier way to do it?

I appreciate your help. Thanks!

like image 256
DemCodeLines Avatar asked Dec 26 '22 14:12

DemCodeLines


1 Answers

Are you looking for something like this?

enter image description here

Here is the code:

Dim pgBarReflection As New Bitmap(ProgressBar1.Width, 20)
ProgressBar1.DrawToBitmap(pgBarReflection, ProgressBar1.ClientRectangle)

For x As Integer = 0 To pgBarReflection.Width - 1
  For y As Integer = 0 To pgBarReflection.Height - 1
    Dim alpha = 255 - 255 * y \ pgBarReflection.Height
    Dim clr As Color = pgBarReflection.GetPixel(x, y)
    clr = Color.FromArgb(alpha, clr.R, clr.G, clr.B)
    pgBarReflection.SetPixel(x, y, clr)
  Next y
Next x

Me.CreateGraphics.DrawImage(pgBarReflection, New Point(ProgressBar1.Left, ProgressBar1.Bottom + 10))

If you want greyscale shadow, replace this line

clr = Color.FromArgb(alpha, clr.R, clr.G, clr.B)

with these two:

Dim greyScale As Integer = CInt(clr.R * 0.3 + clr.G * 0.59 + clr.B * 0.11)
clr = Color.FromArgb(alpha, greyScale, greyScale, greyScale)

You will get something like this:

enter image description here

You can play with parameters to make the shadow more realistic.

Solution is based on this article:

Draw an image with gradient alpha (opacity) values in VB.NET

like image 130
Neolisk Avatar answered Jan 17 '23 17:01

Neolisk