Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleUse a LinearGradientBrush with and without gamma correction in VB .NET
DescriptionThis example shows how to use a LinearGradientBrush with and without gamma correction in VB .NET. Gamma correction adjusts the blended colors to make them have a more uniform brightness.
KeywordsLinearGradientBrush, GammaCorrection, gamma correction, color, drawing, blend
CategoriesVB.NET, Graphics
 
The program makes a LinearGradientBrush that shades colors from black to white between the left and right edges of the form's client area. It then fills a rectangle to show the brush without gamma correction.

Next the program sets the Brush's GammaCorrection property to True and fills a second rectangle below the first one. Gamma correction adjusts the blended colors to make them have a more uniform brightness.

 
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    MyBase.Paint
    ' Make the basic brush.
    Dim x1 As Integer = 10
    Dim x2 As Integer = Me.ClientSize.Width - 10
    Dim the_brush As LinearGradientBrush
    the_brush = New LinearGradientBrush( _
        New Point(x1, 0), New Point(x2, 0), _
        Color.Black, Color.White)

    ' Fill a rectangle without gamma correction.
    e.Graphics.DrawString("Without Gamma Correction", _
        Me.Font, Brushes.Black, x1, 10)
    e.Graphics.FillRectangle(the_brush, x1, 30, x2 - x1, 40)

    ' Fill a rectangle with gamma correction.
    the_brush.GammaCorrection = True
    e.Graphics.FillRectangle(the_brush, x1, 80, x2 - x1, 40)
    e.Graphics.DrawString("With Gamma Correction", _
        Me.Font, Brushes.Black, x1, 125)
End Sub
 
My next book includes a lot more information on Pens, Brushes, and other drawing objects in VS 2005. Check the VB Helper Web site or sign up for my newsletter to learn more about this book when it is available.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated