VB.Net/2D/Gradient

Материал из VB Эксперт
Перейти к: навигация, поиск

Fill an ellipse setting CenterColor and SurroundColors

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class

Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim x As Integer = 10
       Dim y As Integer = 10
       Dim wid As Integer = 100
       Dim hgt As Integer = 50
       " Fill a rectangle.
       Dim rect_pts() As Point = { _
           New Point(x, y), _
           New Point(x + wid, y), _
           New Point(x + wid, y + hgt), _
           New Point(x, y + hgt) _
       }
       Dim path_brush As New PathGradientBrush(rect_pts)
       " Fill an ellipse setting CenterColor and SurroundColors.
       Dim ellipse_path As New GraphicsPath
       ellipse_path.AddEllipse(x, y, wid, hgt)
       path_brush = New PathGradientBrush(ellipse_path)
       path_brush.CenterColor = Color.White
       path_brush.SurroundColors = New Color() {Color.Black}
       e.Graphics.FillEllipse(path_brush, x, y, wid, hgt)
   End Sub

End Class


<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(200, 200)
       Me.Name = "Form1"
       Me.Text = ""
       Me.ResumeLayout(False)
   End Sub

End Class


 </source>


Fill an ellipse using SetBlendTriangularShape

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class

Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim x As Integer = 10
       Dim y As Integer = 10
       Dim wid As Integer = 100
       Dim hgt As Integer = 50
       " Fill a rectangle.
       Dim rect_pts() As Point = { _
           New Point(x, y), _
           New Point(x + wid, y), _
           New Point(x + wid, y + hgt), _
           New Point(x, y + hgt) _
       }
       Dim path_brush As New PathGradientBrush(rect_pts)
       Dim ellipse_path As New GraphicsPath
       " Fill an ellipse using SetBlendTriangularShape.
       ellipse_path = New GraphicsPath
       ellipse_path.AddEllipse(x, y, wid, hgt)
       path_brush = New PathGradientBrush(ellipse_path)
       path_brush.CenterColor = Color.White
       path_brush.SurroundColors = New Color() {Color.Black}
       path_brush.SetBlendTriangularShape(0.5)
       e.Graphics.FillEllipse(path_brush, x, y, wid, hgt)
   End Sub

End Class


<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(200, 200)
       Me.Name = "Form1"
       Me.Text = ""
       Me.ResumeLayout(False)
   End Sub

End Class


 </source>


Fill an ellipse using SetSigmaBellShape

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class

Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim x As Integer = 10
       Dim y As Integer = 10
       Dim wid As Integer = 100
       Dim hgt As Integer = 50
       " Fill a rectangle.
       Dim rect_pts() As Point = { _
           New Point(x, y), _
           New Point(x + wid, y), _
           New Point(x + wid, y + hgt), _
           New Point(x, y + hgt) _
       }
       Dim path_brush As New PathGradientBrush(rect_pts)
       Dim ellipse_path As New GraphicsPath
       " Fill an ellipse using SetSigmaBellShape.
       ellipse_path = New GraphicsPath
       ellipse_path.AddEllipse(x, y, wid, hgt)
       path_brush = New PathGradientBrush(ellipse_path)
       path_brush.CenterColor = Color.White
       path_brush.SurroundColors = New Color() {Color.Black}
       path_brush.SetSigmaBellShape(0.5, 1)
       e.Graphics.FillEllipse(path_brush, x, y, wid, hgt)
   End Sub

End Class


<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(200, 200)
       Me.Name = "Form1"
       Me.Text = ""
       Me.ResumeLayout(False)
   End Sub

End Class


 </source>


Gradient Paint

<source lang="vbnet"> Imports System.Drawing Public Class Form1

   Inherits System.Windows.Forms.Form
   Public Sub New()
       MyBase.New()
       Me.SuspendLayout()
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.BackColor = System.Drawing.Color.Gainsboro
       Me.ClientSize = New System.Drawing.Size(400, 182)
       Me.ResumeLayout(False)
   End Sub
   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       Dim objBrush As New Drawing2D.LinearGradientBrush(Me.DisplayRectangle, Color.Blue, Color.AliceBlue, Drawing2D.LinearGradientMode.Vertical)
       Dim objGraphics As Graphics = Me.CreateGraphics()
       objGraphics.FillRectangle(objBrush, Me.DisplayRectangle)
       objBrush.Dispose()
       objGraphics.Dispose()
   End Sub

End Class


 </source>


Linear Brush: draw ellipse filled with a blue-yellow gradient

<source lang="vbnet"> Imports System Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms Imports System.Drawing.Text Public Class MainClass

  Shared Sub Main()
       Dim myform As Form = New FrmDrawShapes()
       Application.Run(myform)
  End Sub " Main

End Class

Public Class FrmDrawShapes

  Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
  Public Sub New()
     MyBase.New()
     "This call is required by the Windows Form Designer.
     InitializeComponent()
     "Add any initialization after the InitializeComponent() call
  End Sub
  "Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
     If disposing Then
        If Not (components Is Nothing) Then
           components.Dispose()
        End If
     End If
     MyBase.Dispose(disposing)
  End Sub
  "Required by the Windows Form Designer
  Private components As System.ruponentModel.Container
  "NOTE: The following procedure is required by the Windows Form Designer
  "It can be modified using the Windows Form Designer.  
  "Do not modify it using the code editor.
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
     "
     "frmDrawShapes
     "
     Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
     Me.ClientSize = New System.Drawing.Size(520, 197)
     Me.Name = "frmDrawShapes"
     Me.Text = "Drawing Shapes"
  End Sub
  1. End Region
  " draw various shapes on form
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
     " references to object we will use
     Dim graphicsObject As Graphics = e.Graphics
     " ellipse rectangle and gradient brush
     Dim drawArea1 As Rectangle = New Rectangle(5, 35, 30, 100)
     Dim linearBrush As LinearGradientBrush = _
        New LinearGradientBrush(drawArea1, Color.Blue, _
        Color.Yellow, LinearGradientMode.ForwardDiagonal)
     " draw ellipse filled with a blue-yellow gradient
     graphicsObject.FillEllipse(linearBrush, 5, 30, 65, 100)
  End Sub " OnPaint

End Class

 </source>


Linear Gradient Brushes: A diagonal brush

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class


Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim y As Integer = 10
       Dim x As Integer = 10
       Dim wid As Integer = 200
       Dim hgt As Integer = 50
       Dim black_white_brush As New _
           LinearGradientBrush( _
               New Point(x, y), New Point(x + wid, y), _
               Color.Black, Color.White)
       " A diagonal brush.
       wid = hgt
       e.Graphics.DrawString("Diagonal", Me.Font, Brushes.Black, x, y)
       y += 15
       Dim diag_brush As New _
           LinearGradientBrush( _
               New Point(x, y), New Point(x + wid, y + hgt), _
               Color.Black, Color.White)
       e.Graphics.FillRectangle(diag_brush, _
           x, y, wid, hgt)
   End Sub

End Class


<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(800, 400)
       Me.Name = "Form1"
       Me.Text = "TransformArrow"
       Me.ResumeLayout(False)
   End Sub

End Class


 </source>


Linear Gradient Brushes: Change the brush"s WrapMode

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class


Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim y As Integer = 10
       Dim x As Integer = 10
       Dim wid As Integer = 200
       Dim hgt As Integer = 50
       Dim black_white_brush As New _
           LinearGradientBrush( _
               New Point(x, y), New Point(x + wid, y), _
               Color.Black, Color.White)
       Dim short_brush As New _
           LinearGradientBrush( _
               New Point(x, y), New Point(x + 50, y), _
               Color.Black, Color.White)
       " Change the brush"s WrapMode.
       e.Graphics.DrawString("WrapMode = TileFlipX", Me.Font, Brushes.Black, x, y)
       y += 15
       short_brush.WrapMode = WrapMode.TileFlipX
       e.Graphics.FillRectangle(short_brush, _
           x, y, wid, hgt)
   End Sub

End Class


<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(800, 400)
       Me.Name = "Form1"
       Me.Text = "TransformArrow"
       Me.ResumeLayout(False)
   End Sub

End Class


 </source>


Linear Gradient Brushes: Color Blend

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class


Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim y As Integer = 10
       Dim x As Integer = 10
       Dim wid As Integer = 200
       Dim hgt As Integer = 50
       Dim black_white_brush As New _
           LinearGradientBrush( _
               New Point(x, y), New Point(x + wid, y), _
               Color.Black, Color.White)
       " ColorBlend.
       e.Graphics.DrawString("ColorBlend", Me.Font, Brushes.Black, x, y)
       y += 15
       Dim color_blend As New ColorBlend(3)
       color_blend.Colors = New Color() {Color.Black, Color.White, Color.Black}
       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, wid, hgt)
   End Sub

End Class


<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(800, 400)
       Me.Name = "Form1"
       Me.Text = "TransformArrow"
       Me.ResumeLayout(False)
   End Sub

End Class


 </source>


Linear Gradient Brushes: Make a brush that makes 50 percent of the color change

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class


Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim y As Integer = 10
       Dim x As Integer = 10
       Dim wid As Integer = 200
       Dim hgt As Integer = 50
       Dim black_white_brush As New _
           LinearGradientBrush( _
               New Point(x, y), New Point(x + wid, y), _
               Color.Black, Color.White)
       " ColorBlend.
       " Make a brush that makes 50 percent of the color change
       " in the first 20 percent of the distance, stays there
       " until 80 percent of the distance, and then finishes
       " in the remaining distance.
       e.Graphics.DrawString("Blend", Me.Font, Brushes.Black, x, y)
       y += 15
       Dim the_blend As New Blend(4)
       the_blend.Factors = New Single() {0.0, 0.5, 0.5, 1.0}
       the_blend.Positions = New Single() {0.0, 0.2, 0.8, 1.0}
       black_white_brush.Blend = the_blend
       e.Graphics.FillRectangle(black_white_brush, _
           x, y, wid, hgt)
   End Sub

End Class


<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(800, 400)
       Me.Name = "Form1"
       Me.Text = "TransformArrow"
       Me.ResumeLayout(False)
   End Sub

End Class


 </source>


Linear Gradient Brushes: Normal, Triangle, Bell and custom color

<source lang="vbnet"> Imports System Imports System.Collections Imports System.ruponentModel Imports System.Windows.Forms Imports System.Data Imports System.Configuration Imports System.Resources Imports System.Drawing Imports System.Drawing.Drawing2D Public Class MainClass

   Shared Sub Main()
       Dim myform As Form = New LinearGradientBrushesForm()
       Application.Run(myform)
   End Sub

End Class Public Class LinearGradientBrushesForm

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       components = New System.ruponentModel.Container()
       Me.Text = "LinearGradientBrushesForm"
   End Sub
  1. End Region
   Private Sub LinearGradientBrushesForm_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
       Dim g As Graphics = e.Graphics
       Dim x As Integer = 0
       Dim y As Integer = 0
       Dim width As Integer = Me.ClientRectangle.Width
       Dim height As Integer = Me.ClientRectangle.Height / 4
       Dim blackBrush As Brush = Brushes.Black
       Dim b As LinearGradientBrush = New LinearGradientBrush(Me.ClientRectangle, Color.White, Color.Black, LinearGradientMode.Horizontal)
       g.FillRectangle(b, x, y, width, height)
       g.DrawString("Normal", Me.Font, blackBrush, x, y)
       y = y + height
       b.SetBlendTriangularShape(0.5)
       g.FillRectangle(b, x, y, width, height)
       g.DrawString("Triangle", Me.Font, blackBrush, x, y)
       y = y + height
       b.SetSigmaBellShape(0.5)
       g.FillRectangle(b, x, y, width, height)
       g.DrawString("Bell", Me.Font, blackBrush, x, y)
       y = y + height
       Dim blend As ColorBlend = New ColorBlend()
       blend.Colors = New Color() {Color.White, Color.Red, Color.Black}
       blend.Positions = New Single() {0.0, 0.5, 1.0}
       b.InterpolationColors = blend
       g.FillRectangle(b, x, y, width, height)
       g.DrawString("Custom Colors", Me.Font, blackBrush, x, y)
       y = y + height
   End Sub

End Class


 </source>


Linear Gradient Brushes: Sigma bell shape

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class


Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim y As Integer = 10
       Dim x As Integer = 10
       Dim wid As Integer = 200
       Dim hgt As Integer = 50
       Dim black_white_brush As New _
           LinearGradientBrush( _
               New Point(x, y), New Point(x + wid, y), _
               Color.Black, Color.White)
       " Sigma bell shape.
       e.Graphics.DrawString("SetSigmaBellShape", Me.Font, Brushes.Black, x, y)
       y += 15
       black_white_brush.SetSigmaBellShape(0.5, 1)
       e.Graphics.FillRectangle(black_white_brush, _
           x, y, wid, hgt)
   End Sub

End Class


<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(800, 400)
       Me.Name = "Form1"
       Me.Text = "TransformArrow"
       Me.ResumeLayout(False)
   End Sub

End Class


 </source>


Linear Gradient Brushes: This brush"s line is too short to cross the whole rectangle

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class


Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim y As Integer = 10
       Dim x As Integer = 10
       Dim wid As Integer = 200
       Dim hgt As Integer = 50
       Dim black_white_brush As New _
           LinearGradientBrush( _
               New Point(x, y), New Point(x + wid, y), _
               Color.Black, Color.White)
       " This brush"s line is too short to cross the whole rectangle.
       e.Graphics.DrawString("Short", Me.Font, Brushes.Black, x, y)
       y += 15
       Dim short_brush As New _
           LinearGradientBrush( _
               New Point(x, y), New Point(x + 50, y), _
               Color.Black, Color.White)
       e.Graphics.FillRectangle(short_brush, _
           x, y, wid, hgt)
   End Sub

End Class


<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(800, 400)
       Me.Name = "Form1"
       Me.Text = "TransformArrow"
       Me.ResumeLayout(False)
   End Sub

End Class


 </source>


Linear Gradient Brushes: Trangular brush

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class


Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim y As Integer = 10
       Dim x As Integer = 10
       Dim wid As Integer = 200
       Dim hgt As Integer = 50
       Dim black_white_brush As New _
           LinearGradientBrush( _
               New Point(x, y), New Point(x + wid, y), _
               Color.Black, Color.White)
       " Trangular brush.
       e.Graphics.DrawString("SetBlendTriangularShape", Me.Font, Brushes.Black, x, y)
       y += 15
       black_white_brush.SetBlendTriangularShape(0.5)
       e.Graphics.FillRectangle(black_white_brush, _
           x, y, wid, hgt)
   End Sub

End Class


<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(800, 400)
       Me.Name = "Form1"
       Me.Text = "TransformArrow"
       Me.ResumeLayout(False)
   End Sub

End Class


 </source>


Make a rectangle that shades from black to white

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class


Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim y As Integer = 10
       Dim x As Integer = 10
       Dim wid As Integer = 200
       Dim hgt As Integer = 50
       " Make a rectangle that shades from black to white.
       e.Graphics.DrawString("Simple", Me.Font, Brushes.Black, x, y)
       y += 15
       Dim black_white_brush As New _
           LinearGradientBrush( _
               New Point(x, y), New Point(x + wid, y), _
               Color.Black, Color.White)
       e.Graphics.FillRectangle(black_white_brush, _
           x, y, wid, hgt)
       y += hgt + 10
   End Sub

End Class


<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(800, 400)
       Me.Name = "Form1"
       Me.Text = "TransformArrow"
       Me.ResumeLayout(False)
   End Sub

End Class


 </source>


Path Gradient Brushes: Diamond, Rectangle, Cirlce and quad

<source lang="vbnet"> Imports System Imports System.Collections Imports System.ruponentModel Imports System.Windows.Forms Imports System.Data Imports System.Configuration Imports System.Resources Imports System.Drawing Imports System.Drawing.Drawing2D Public Class MainClass

   Shared Sub Main()
       Dim myform As Form = New PathGradientBrushesForm()
       Application.Run(myform)
   End Sub

End Class Public Class PathGradientBrushesForm

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       components = New System.ruponentModel.Container()
       Me.Text = "PathGradientBrushesForm"
   End Sub
  1. End Region
   Private Sub PathGradientBrushesForm_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
       Dim g As Graphics = e.Graphics
       Dim width As Integer = Me.ClientRectangle.Width / 2
       Dim height As Integer = Me.ClientRectangle.Height / 2
       Dim triPoints As Point() = New Point() {New Point(width / 2, 0), New Point(0, height), New Point(width, height)}
       Dim b As PathGradientBrush = New PathGradientBrush(triPoints)
       b.SurroundColors = New Color() {Color.Red, Color.Blue}
       Dim x As Integer = 0
       Dim y As Integer = 0
       g.FillRectangle(b, x, y, width, height)
       Dim quadPoints As Point() = New Point() {New Point(0, 0), New Point(width, 0), New Point(width, height), New Point(0, height)}
       b = New PathGradientBrush(quadPoints)
       b.WrapMode = WrapMode.Tile
       x = width
       y = 0
       g.FillRectangle(b, x, y, width, height)
       Dim diamondPoints As Point() = New Point() {New Point(width / 2, 0), New Point(width, height / 2), New Point(width / 2, height), New Point(0, height / 2)}
       b = New PathGradientBrush(diamondPoints)
       b.WrapMode = WrapMode.Tile
       b.CenterPoint = New PointF(0, height / 2)
       x = 0
       y = height
       g.FillRectangle(b, x, y, width, height)
       Dim circle As GraphicsPath = New GraphicsPath()
       circle.AddEllipse(0, 0, width, height)
       b = New PathGradientBrush(circle)
       b.WrapMode = WrapMode.Tile
       b.SurroundColors = New Color() {Color.White}
       b.CenterColor = Color.Black
       x = width
       y = height
       g.FillRectangle(b, x, y, width, height)
   End Sub

End Class


 </source>


Path Gradient Brush: rectangle

<source lang="vbnet"> Imports System.Drawing.Drawing2D Imports System Imports System.Drawing.Text Imports System.Drawing Imports System.Windows.Forms Imports System.Math Public Class MainClass

  Shared Sub Main()
      Dim form1 As Form = New Form1()
      Application.Run(form1)
  End Sub 

End Class


Public Class Form1

   Private Sub Form1_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
       Dim x As Integer = 10
       Dim y As Integer = 10
       Dim wid As Integer = 100
       Dim hgt As Integer = 50
       " Fill a rectangle.
       Dim rect_pts() As Point = { _
           New Point(x, y), _
           New Point(x + wid, y), _
           New Point(x + wid, y + hgt), _
           New Point(x, y + hgt) _
       }
       Dim path_brush As New PathGradientBrush(rect_pts)
       e.Graphics.FillPolygon(path_brush, rect_pts)
       y += hgt + 10
   End Sub

End Class


<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1

   Inherits System.Windows.Forms.Form
   "Form overrides dispose to clean up the component list.
   <System.Diagnostics.DebuggerNonUserCode()> _
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing AndAlso components IsNot Nothing Then
           components.Dispose()
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> _
   Private Sub InitializeComponent()
       Me.SuspendLayout()
       "
       "Form1
       "
       Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
       Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
       Me.ClientSize = New System.Drawing.Size(200, 200)
       Me.Name = "Form1"
       Me.Text = ""
       Me.ResumeLayout(False)
   End Sub

End Class


 </source>