Degrade color panel - (Gradient)

This time I want to show a simple way to have a much more attractive panel with a gradient of two colors in visual basic. net .

For example we need a form and a panel, as shown in the following figure:

We then double-click the panel and go to paint the panel event in the code view, and this event put the following code:

 Dim y As Integer = 0
 Dim x As Integer = 0
 Dim width As Integer = Me.Width
 Dim high As Integer = Me.Height
 Dim color1 As Color
 Dim color2 As Color

 color1 = Color.DarkRed
 color2 = Color.LightCoral

 Dim color As New _
 LinearGradientBrush (_
 New Point (x, y), New Point (x + width, y), _
 color1, color2)
 e.Graphics.FillRectangle (coloring, _
 x, y, width, height)
 y + = height + 10

For this work we add a code reference Drawing2D as shown below:

 Imports System.Drawing.Drawing2D

Running the program should see a form with a look similar to the following figure:

Changing the values ​​of the variables color1 and color2 can change the results to your liking.

Also I want to leave then a couple of variants for the event code reemplaar panel paint and get different results ... I hope you try them and they like ...

Option 1

 Dim y As Integer = 0
 Dim x As Integer = 0
 Dim width As Integer = Me.Width
 Dim high As Integer = Me.Height
 Dim color1 As Color
 Dim color2 As Color

 color1 = Color.DarkRed
 color2 = Color.LightCoral

 Dim As New _ black_white_brush
 LinearGradientBrush (_
 New Point (x, y), New Point (x + width, y), _
 color1, color2)

 Dim As New ColorBlend color_blend (3)
 color_blend.Colors = New Color () {color1, color2, color1}
 color_blend.Positions = New Single () {0.0, 0.2, 1.0}
 black_white_brush.InterpolationColors = color_blend
 e.Graphics.FillRectangle (black_white_brush, _
 x, y, width, height)

Option 2

 Dim y As Integer = 0
 Dim x As Integer = 0
 Dim width As Integer = Me.Width
 Dim high As Integer = Me.Height
 Dim color1 As Color
 Dim color2 As Color

 color1 = Color.DarkRed
 color2 = Color.LightCoral

 Dim color As New _
 LinearGradientBrush (_
 New Point (x, y), New Point (x + width, y), _
 color1, color2)

 Dim As New _ diag_brush
 LinearGradientBrush (_
 New Point (x, y), New Point (x + width, y + height), _
 color1, color2)
 e.Graphics.FillRectangle (diag_brush, _
 x, y, width, height)

If you served, please leave a comment. Regards

9 Responses to "Panel with color degradation - (Gradient)"

  1. Information Bitacoras.com ...

    Rate in Bitacoras.com: I want to show at this time very easily have a much more attractive panel with a gradient of two colors. For example we need a form and a panel, as shown in the figure below: ...

  2. Hamilton says:

    looking for something, and has served me well ... greetings

  3. Carlos Claudio says:

    Hello to All
    Thanks for the code, I am a student of computer science and served me well this code, as it is always good to have our forms look good, so I will not have to be looking for some wallpaper.
    Total Thanks

    Carlos Claudio

  4. Jb says:

    Q good code, I could attach it to a class I did q the gradient background ... Thanks, it is possible someone knew how to do q visible / invisible paulatinemente?

    Thanks again

  5. ADAL says:

    INSERT CODE TO MAKE ME AN ERROR

    Error 1 'Graphics' is not a member of 'System.EventArgs'.

  6. poncianux says:

    wow, just what I need for my application I'll see if I can make it Vertical

  7. poncianux says:

    vertically to change me laugh to know that you just have to delete a word and put another, helped me thanks!

  8. Cristyan says:

    Very good post, I discovered a few hours ago and I have done both VB and C #, simple and concise. Very good, Greetings.

Comment