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
 
 
 
 
 
TitleDisplay the standard linear gradient styles in VB .NET
DescriptionThis example shows how to display the standard linear gradient styles in VB .NET. It iterates through the LinearGradientMode values, displaying examples of each.
KeywordsLinearGradientMode, linear gradient, gradient, VB.NET, brush
CategoriesVB.NET, Graphics
 
The program loops through each of the numeric LinearGradientMode values, calling DrawGradientSample.

Subroutine DrawGradientSample draws the LinearGradientMode's name and a rectangle filled with that style.

 
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    MyBase.Paint
    ' Currently the linear gradient modes have values 0 to
    ' 3.
    Const MIN_MODE As Integer = 0
    Const MAX_MODE As Integer = 3
    Dim x As Integer = 10
    Dim y As Integer = 10

    For i As Integer = MIN_MODE To MAX_MODE
        DrawGradientSample(e.Graphics, x, y, CType(i, _
            LinearGradientMode))
    Next i
End Sub

Private Sub DrawGradientSample(ByVal gr As Graphics, ByRef _
    x As Integer, ByRef y As Integer, ByVal gradient_mode _
    As LinearGradientMode)
    Const TEXT_WID As Integer = 155
    Const RECT_WID As Integer = 100
    Const RECT_HGT As Integer = 100
    Dim rect As New Rectangle( _
        x + TEXT_WID, y, RECT_WID, RECT_HGT)
    Dim br As New LinearGradientBrush( _
        rect, Color.Blue, Color.Red, gradient_mode)
    gr.DrawString( _
        gradient_mode.ToString & " (" & CInt(gradient_mode) _
            & ")", _
        Me.Font, Brushes.Black, x, y)
    gr.FillRectangle(br, rect)
    gr.DrawRectangle(Pens.Black, rect)

    y += RECT_HGT + 10
    If y + RECT_HGT > Me.ClientSize.Height Then
        x += TEXT_WID + RECT_WID + 30
        y = 10
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated