VB.Net/2D/Gradient — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:41, 26 мая 2010
Содержание
- 1 Fill an ellipse setting CenterColor and SurroundColors
- 2 Fill an ellipse using SetBlendTriangularShape
- 3 Fill an ellipse using SetSigmaBellShape
- 4 Gradient Paint
- 5 Linear Brush: draw ellipse filled with a blue-yellow gradient
- 6 Linear Gradient Brushes: A diagonal brush
- 7 Linear Gradient Brushes: Change the brush"s WrapMode
- 8 Linear Gradient Brushes: Color Blend
- 9 Linear Gradient Brushes: Make a brush that makes 50 percent of the color change
- 10 Linear Gradient Brushes: Normal, Triangle, Bell and custom color
- 11 Linear Gradient Brushes: Sigma bell shape
- 12 Linear Gradient Brushes: This brush"s line is too short to cross the whole rectangle
- 13 Linear Gradient Brushes: Trangular brush
- 14 Make a rectangle that shades from black to white
- 15 Path Gradient Brushes: Diamond, Rectangle, Cirlce and quad
- 16 Path Gradient Brush: rectangle
Fill an ellipse setting CenterColor and SurroundColors
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
Fill an ellipse using SetBlendTriangularShape
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
Fill an ellipse using SetSigmaBellShape
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
Gradient Paint
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
Linear Brush: draw ellipse filled with a blue-yellow gradient
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
#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
#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
Linear Gradient Brushes: A diagonal brush
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
Linear Gradient Brushes: Change the brush"s WrapMode
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
Linear Gradient Brushes: Color Blend
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
Linear Gradient Brushes: Make a brush that makes 50 percent of the color change
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
Linear Gradient Brushes: Normal, Triangle, Bell and custom color
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
#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
#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
Linear Gradient Brushes: Sigma bell shape
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
Linear Gradient Brushes: This brush"s line is too short to cross the whole rectangle
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
Linear Gradient Brushes: Trangular brush
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
Make a rectangle that shades from black to white
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
Path Gradient Brushes: Diamond, Rectangle, Cirlce and quad
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
#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
#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
Path Gradient Brush: rectangle
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