Imports System.Drawing.Drawing2D Public Class Form1 ' Fill a rectangle with a linear gradient brush. Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint ' Draw with a horizontal gradient. Dim rect1 As New Rectangle(20, 20, 250, 100) Using br As New LinearGradientBrush( _ rect1, Color.Red, Color.Blue, LinearGradientMode.Horizontal) e.Graphics.FillRectangle(br, rect1) e.Graphics.DrawRectangle(Pens.Black, rect1) End Using '' Draw with a horizontal gradient. 'Dim rect2 As New Rectangle(20, 140, 250, 100) 'Using br As New LinearGradientBrush( _ ' rect2, Color.Red, Color.Blue, LinearGradientMode.Horizontal) ' ' Define a rainbow blend. ' Dim color_blend As New ColorBlend() ' color_blend.Colors = New Color() _ ' {Color.Red, Color.Orange, Color.Yellow, _ ' Color.Lime, Color.Blue, Color.Indigo, Color.DarkViolet} ' color_blend.Positions = New Single() _ ' {0 / 6, 1 / 6, 2 / 6, 3 / 6, 4 / 6, 5 / 6, 6 / 6} ' br.InterpolationColors = color_blend ' ' Fill a rectangle with the blended brush. ' e.Graphics.FillRectangle(br, rect2) ' e.Graphics.DrawRectangle(Pens.Black, rect2) 'End Using End Sub End Class |