Title | Display the standard linear gradient styles in VB .NET |
Description | This example shows how to display the standard linear gradient styles in VB .NET. It iterates through the LinearGradientMode values, displaying examples of each. |
Keywords | LinearGradientMode, linear gradient, gradient, VB.NET, brush |
Categories | VB.NET, Graphics |
|
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
|