Mirror Text: use Drawing2D.Matrix to transform Graphics : Matrix « 2D Graphics « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » 2D Graphics » Matrix 
17.87.9.Mirror Text: use Drawing2D.Matrix to transform Graphics
'Visual Basic 2005 Cookbook Solutions for VB 2005 Programmers
'by Tim Patrick (Author), John Craig (Author)
'# Publisher: O'Reilly Media, Inc. (September 212006)
'# Language: English
'# ISBN-100596101775
'# ISBN-13978-0596101770


Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class MirrorText
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1
    Private Const QuoteText As String = "www.java2java.com"

    Private Sub VerticalMirror_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgsHandles VerticalMirror.CheckedChanged
        MirroredText.Invalidate()
    End Sub

    Private Sub MirroredText_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgsHandles MirroredText.Paint
        Dim drawingArea As Rectangle
        Dim saveState As Drawing2D.GraphicsState
        Dim mirrorMatrix As Drawing2D.Matrix

        e.Graphics.Clear(Color.White)

        If (VerticalMirror.Checked = TrueThen
            drawingArea = New Rectangle(55, _
                (MirroredText.ClientRectangle.Width \ 210, _
                MirroredText.ClientRectangle.Height - 10)

            e.Graphics.DrawLine(Pens.Black, MirroredText.ClientRectangle.Width \ 2, _
                5, MirroredText.ClientRectangle.Width \ 2, _
                MirroredText.ClientRectangle.Height - 10)
        Else
            drawingArea = New Rectangle(55, _
                MirroredText.ClientRectangle.Width - 10, _
                (MirroredText.ClientRectangle.Height \ 210)

            e.Graphics.DrawLine(Pens.Black, 5, _
                MirroredText.ClientRectangle.Height \ 2, _
                MirroredText.ClientRectangle.Width - 10, _
                MirroredText.ClientRectangle.Height \ 2)
        End If

        e.Graphics.DrawString(QuoteText, MirroredText.Font, _
            Brushes.Black, drawingArea)

        saveState = e.Graphics.Save()
        If (VerticalMirror.Checked = TrueThen
            mirrorMatrix = New Drawing2D.Matrix(-1001, MirroredText.ClientRectangle.Width, 0)
        Else
            mirrorMatrix = New Drawing2D.Matrix(100, -10, MirroredText.ClientRectangle.Height)
        End If

        e.Graphics.Transform = mirrorMatrix

        e.Graphics.DrawString(QuoteText, MirroredText.Font, _
            Brushes.Black, drawingArea)
        e.Graphics.Restore(saveState)
    End Sub
End Class


<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected 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.ComponentModel.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.VerticalMirror = New System.Windows.Forms.RadioButton
        Me.MirroredText = New System.Windows.Forms.PictureBox
        Me.HorizontalMirror = New System.Windows.Forms.RadioButton
        CType(Me.MirroredText, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'VerticalMirror
        '
        Me.VerticalMirror.AutoSize = True
        Me.VerticalMirror.Checked = True
        Me.VerticalMirror.Location = New System.Drawing.Point(88)
        Me.VerticalMirror.Name = "VerticalMirror"
        Me.VerticalMirror.Size = New System.Drawing.Size(6017)
        Me.VerticalMirror.TabIndex = 0
        Me.VerticalMirror.TabStop = True
        Me.VerticalMirror.Text = "&Vertical"
        Me.VerticalMirror.UseVisualStyleBackColor = True
        '
        'MirroredText
        '
        Me.MirroredText.BackColor = System.Drawing.Color.White
        Me.MirroredText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.MirroredText.Location = New System.Drawing.Point(1048)
        Me.MirroredText.Name = "MirroredText"
        Me.MirroredText.Size = New System.Drawing.Size(304168)
        Me.MirroredText.TabIndex = 1
        Me.MirroredText.TabStop = False
        '
        'HorizontalMirror
        '
        Me.HorizontalMirror.AutoSize = True
        Me.HorizontalMirror.Location = New System.Drawing.Point(832)
        Me.HorizontalMirror.Name = "HorizontalMirror"
        Me.HorizontalMirror.Size = New System.Drawing.Size(7217)
        Me.HorizontalMirror.TabIndex = 1
        Me.HorizontalMirror.Text = "&Horizontal"
        Me.HorizontalMirror.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(419187)
        Me.Controls.Add(Me.HorizontalMirror)
        Me.Controls.Add(Me.MirroredText)
        Me.Controls.Add(Me.VerticalMirror)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.Name = "Form1"
        Me.Text = "Mirror Text"
        CType(Me.MirroredText, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents VerticalMirror As System.Windows.Forms.RadioButton
    Friend WithEvents MirroredText As System.Windows.Forms.PictureBox
    Friend WithEvents HorizontalMirror As System.Windows.Forms.RadioButton

End Class
17.87.Matrix
17.87.1.Matrix: TranslateMatrix: Translate
17.87.2.Matrix: RotateAtMatrix: RotateAt
17.87.3.Matrix.InvertMatrix.Invert
17.87.4.Matrix: Shear(0,0)Matrix: Shear(0,0)
17.87.5.Matrix: Shear(0.5,0.0)Matrix: Shear(0.5,0.0)
17.87.6.Matrix: Shear(1,0)Matrix: Shear(1,0)
17.87.7.Matrix Operation Invert
17.87.8.Matrix Operation Multiply
17.87.9.Mirror Text: use Drawing2D.Matrix to transform Graphics
17.87.10.Assign Matrix to Graphics.TransformAssign Matrix to Graphics.Transform
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.