VB.Net/2D/Scale
Содержание
Matrix Scale Demo
Imports System
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Globalization
Imports System.Text
Imports System.Collections
Public Class MainClass
Shared Sub Main()
Dim myform As Form = New MatrixMarginsForm()
Application.Run(myform)
End Sub
End Class
Public Class MatrixMarginsForm
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.
Friend WithEvents statusBar1 As System.Windows.Forms.StatusBar
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.statusBar1 = New System.Windows.Forms.StatusBar()
Me.SuspendLayout()
"
"statusBar1
"
Me.statusBar1.Location = New System.Drawing.Point(0, 244)
Me.statusBar1.Name = "statusBar1"
Me.statusBar1.Size = New System.Drawing.Size(292, 22)
Me.statusBar1.TabIndex = 1
Me.statusBar1.Text = "statusBar1"
"
"MatrixMarginsForm
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.statusBar1})
Me.Name = "MatrixMarginsForm"
Me.Text = "MatrixMarginsForm"
Me.ResumeLayout(False)
End Sub
#End Region
Sub ScaleExample(ByVal e As PaintEventArgs)
Dim myPen As Pen = New Pen(Color.Blue, 1)
Dim myPen2 As Pen = New Pen(Color.Red, 1)
e.Graphics.DrawRectangle(myPen, 5, 5, 10, 10)
Dim myMatrix As Matrix = New Matrix()
myMatrix.Scale(3, 2, MatrixOrder.Append)
e.Graphics.Transform = myMatrix
e.Graphics.DrawRectangle(myPen2, 5, 5, 10, 10)
End Sub
Sub Margins_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
ScaleExample(e)
End Sub
End Class
==Scale:/td>
Imports System
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Globalization
Imports System.Text
Imports System.Collections
Public Class MainClass
Shared Sub Main()
Dim myform As Form = New ScalingFontsForm()
Application.Run(myform)
End Sub
End Class
Public Class ScalingFontsForm
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()
"
"ScalingFontsForm
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(512, 70)
Me.Name = "ScalingFontsForm"
Me.Text = "ScalingFontsForm"
End Sub
#End Region
Sub ScalingFontsForm_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
Dim format As StringFormat = New StringFormat()
format.Alignment = StringAlignment.Center
format.LineAlignment = StringAlignment.Center
Dim matrix As Matrix = New Matrix()
g.ResetTransform()
g.DrawRectangle(Pens.Black, x, y, width, height)
matrix.Reset()
matrix.Scale(1, 1)
g.Transform = matrix
g.DrawString("Scale(1,1)", Me.Font, Brushes.Black, New RectangleF(x, y, width, height), format)
x = IIf(x > Me.ClientRectangle.Width - 2 * width, 0, x + width)
y = IIf(x = 0, y + height, y)
End Sub
End Class
==Scale:/td>
Imports System
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Globalization
Imports System.Text
Imports System.Collections
Public Class MainClass
Shared Sub Main()
Dim myform As Form = New ScalingFontsForm()
Application.Run(myform)
End Sub
End Class
Public Class ScalingFontsForm
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()
"
"ScalingFontsForm
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(512, 70)
Me.Name = "ScalingFontsForm"
Me.Text = "ScalingFontsForm"
End Sub
#End Region
Sub ScalingFontsForm_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
Dim format As StringFormat = New StringFormat()
format.Alignment = StringAlignment.Center
format.LineAlignment = StringAlignment.Center
Dim matrix As Matrix = New Matrix()
g.ResetTransform()
g.DrawRectangle(Pens.Black, x, y, width, height)
matrix.Reset()
matrix.Scale(1, 3)
g.Transform = matrix
g.DrawString("Scale(1,3)", Me.Font, Brushes.Black, New RectangleF(x, y / 3.0F, width, height / 3.0F), format)
x = IIf(x > Me.ClientRectangle.Width - 2 * width, 0, x + width)
y = IIf(x = 0, y + height, y)
End Sub
End Class
==Scale:/td>
Imports System
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Globalization
Imports System.Text
Imports System.Collections
Public Class MainClass
Shared Sub Main()
Dim myform As Form = New ScalingFontsForm()
Application.Run(myform)
End Sub
End Class
Public Class ScalingFontsForm
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()
"
"ScalingFontsForm
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(512, 70)
Me.Name = "ScalingFontsForm"
Me.Text = "ScalingFontsForm"
End Sub
#End Region
Sub ScalingFontsForm_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
Dim format As StringFormat = New StringFormat()
format.Alignment = StringAlignment.Center
format.LineAlignment = StringAlignment.Center
Dim matrix As Matrix = New Matrix()
g.ResetTransform()
g.DrawRectangle(Pens.Black, x, y, width, height)
matrix.Reset()
matrix.Scale(3, 1)
g.Transform = matrix
g.DrawString("Scale(3,1)", Me.Font, Brushes.Black, New RectangleF(x / 3.0F, y, width / 3.0F, height), format)
x = IIf(x > Me.ClientRectangle.Width - 2 * width, 0, x + width)
y = IIf(x = 0, y + height, y)
End Sub
End Class
Scale by a factor of 30
Imports System.Drawing.Drawing2D
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1()
Application.Run(form1)
End Sub " ValidationError
End Class
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
" Scale by a factor of 30.
e.Graphics.ScaleTransform(30, 30, MatrixOrder.Append)
DrawArrow(e.Graphics, HatchStyle.Horizontal)
End Sub
" Draw an arrow outline.
Private Sub DrawArrow(ByVal gr As Graphics, ByVal hatch_style As HatchStyle)
Dim pts() As Point = { _
New Point(0, 1), _
New Point(2, 1), _
New Point(2, 0), _
New Point(4, 2), _
New Point(2, 4), _
New Point(2, 3), _
New Point(0, 3) _
}
gr.FillPolygon(New HatchBrush(hatch_style, Color.Black, Color.White), pts)
gr.DrawPolygon(New Pen(Color.Black, 0), pts)
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(292, 273)
Me.Name = "Form1"
Me.Text = "TransformArrow"
Me.ResumeLayout(False)
End Sub
End Class
Scale by a factor of 30 and Rotate 30 degrees
Imports System.Drawing.Drawing2D
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1()
Application.Run(form1)
End Sub " ValidationError
End Class
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
e.Graphics.ScaleTransform(30, 30, MatrixOrder.Append)
" Rotate 30 degrees.
e.Graphics.RotateTransform(30, MatrixOrder.Append)
DrawArrow(e.Graphics, HatchStyle.Cross)
End Sub
" Draw an arrow outline.
Private Sub DrawArrow(ByVal gr As Graphics, ByVal hatch_style As HatchStyle)
Dim pts() As Point = { _
New Point(0, 1), _
New Point(2, 1), _
New Point(2, 0), _
New Point(4, 2), _
New Point(2, 4), _
New Point(2, 3), _
New Point(0, 3) _
}
gr.FillPolygon(New HatchBrush(hatch_style, Color.Black, Color.White), pts)
gr.DrawPolygon(New Pen(Color.Black, 0), pts)
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(292, 273)
Me.Name = "Form1"
Me.Text = "TransformArrow"
Me.ResumeLayout(False)
End Sub
End Class
Scale by a factor of 30 and Translate 150 horizontally and 60 vertically
Imports System.Drawing.Drawing2D
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1()
Application.Run(form1)
End Sub " ValidationError
End Class
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
" Translate 150 horizontally and 60 vertically.
e.Graphics.ScaleTransform(30, 30, MatrixOrder.Append)
e.Graphics.TranslateTransform(150, 60, MatrixOrder.Append)
DrawArrow(e.Graphics, HatchStyle.Vertical)
End Sub
" Draw an arrow outline.
Private Sub DrawArrow(ByVal gr As Graphics, ByVal hatch_style As HatchStyle)
Dim pts() As Point = { _
New Point(0, 1), _
New Point(2, 1), _
New Point(2, 0), _
New Point(4, 2), _
New Point(2, 4), _
New Point(2, 3), _
New Point(0, 3) _
}
gr.FillPolygon(New HatchBrush(hatch_style, Color.Black, Color.White), pts)
gr.DrawPolygon(New Pen(Color.Black, 0), pts)
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(292, 273)
Me.Name = "Form1"
Me.Text = "TransformArrow"
Me.ResumeLayout(False)
End Sub
End Class
Scale Transform Demo
Imports System
Imports System.Windows.Forms
Imports System.Drawing.Text
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class MainClass
Shared Sub Main(ByVal args As String())
Dim myform As Form = New Form1()
Application.Run(myform)
End Sub
End Class
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim device_rect As New Rectangle(50, 50, 150, 150)
e.Graphics.DrawRectangle(Pens.Black, device_rect)
Dim world_rect As New Rectangle(0, 0, 1, 1)
MapRectangles(e.Graphics, world_rect, device_rect)
Dim the_pen As New Pen(Color.Black, 0)
e.Graphics.FillEllipse(Brushes.Yellow, 0, 0, 1, 1) " Face.
e.Graphics.DrawEllipse(the_pen, 0, 0, 10, 10)
End Sub
" Map a world coordinate rectangle to a device coordinate rectangle.
Private Sub MapRectangles(ByVal gr As Graphics, ByVal world_rect As Rectangle, ByVal device_rect As Rectangle)
gr.ResetTransform()
gr.ScaleTransform( _
CSng(device_rect.Width / world_rect.Width), _
CSng(device_rect.Height / world_rect.Height), _
MatrixOrder.Append)
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(564, 209)
Me.Name = "Form1"
Me.Text = "Title"
Me.ResumeLayout(False)
End Sub
End Class
Shear: 0,0
Imports System
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Globalization
Imports System.Text
Imports System.Collections
Public Class MainClass
Shared Sub Main()
Dim myform As Form = New ShearingForm()
Application.Run(myform)
End Sub
End Class
Public Class ShearingForm
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 = "ShearingForm"
End Sub
#End Region
Sub ShearingForm_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics = e.Graphics
Dim width As Single = 200
Dim height As Single = 50
Dim format As StringFormat = New StringFormat()
format.Alignment = StringAlignment.Center
format.LineAlignment = StringAlignment.Center
Dim rect As RectangleF = New RectangleF(0, 0, width, height)
Dim matrix As Matrix = New Matrix()
matrix.Translate(0, 0)
matrix.Shear(0.0F, 0.0F)
g.Transform = matrix
g.DrawString("Shear(0,0)", Me.Font, Brushes.Black, rect, format)
g.DrawRectangle(Pens.Black, rect.X, rect.Y, rect.Width, rect.Height)
End Sub
End Class