File size: 4,341 Bytes
b1b3bae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
'Copyright (C) 2002 Microsoft Corporation
'All rights reserved.
'
'THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
'EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
'MERCHANTIBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'
'Date: June 2002
'Author: Duncan Mackenzie
'
'Requires the release version of .NET Framework

Imports System.Drawing

Namespace GraphicObjects

    <Serializable()> _
    Public Class TextGraphic
        Inherits GraphicObject

        Protected m_Font As Font = System.Drawing.SystemFonts.DefaultFont
        Protected m_Text As String = ""
        Protected m_Color As Color = Drawing.Color.Black
        Protected m_TextRenderStyle As Drawing2D.SmoothingMode = Drawing2D.SmoothingMode.Default

#Region "Constructors"

        Public Sub New()
            MyBase.New()
            Me.ObjectType = Interfaces.Enums.GraphicObjects.ObjectType.GO_Text
        End Sub

        Public Sub New(ByVal graphicPosition As Point, ByVal text As String, _
                ByVal textFont As Font, ByVal textColor As Color)
            Me.New()
            Me.SetPosition(graphicPosition)
            Me.Font = textFont
            Me.Text = text
            Me.Color = textColor
        End Sub

        Public Sub New(ByVal posX As Integer, ByVal posY As Integer, _
            ByVal text As String, ByVal textFont As Font, ByVal textColor As Color)
            Me.New(New Point(posX, posY), text, textFont, textColor)
        End Sub


        Public Sub New(ByVal graphicPosition As Point, _
                ByVal text As String, ByVal textFont As Font, _
                ByVal textColor As Color, ByVal Rotation As Single)
            Me.New(graphicPosition, text, textFont, textColor)
            Me.Rotation = Rotation
        End Sub

        Public Sub New(ByVal posX As Integer, ByVal posY As Integer, _
                ByVal text As String, _
                ByVal textFont As Font, _
                ByVal textColor As Color, ByVal Rotation As Single)
            Me.New(New Point(posX, posY), text, textFont, textColor, Rotation)
        End Sub
#End Region

        Public Property Font() As Font
            Get
                Return m_Font
            End Get
            Set(ByVal Value As Font)
                m_Font = Value
            End Set
        End Property

        Public Property Text() As String
            Get
                Return m_Text
            End Get
            Set(ByVal Value As String)
                m_Text = Value
            End Set
        End Property

        Public Property Color() As System.Drawing.Color
            Get
                Return m_Color
            End Get
            Set(ByVal Value As System.Drawing.Color)
                m_Color = Value
            End Set
        End Property

        Public Property TextRenderStyle() As Drawing2D.SmoothingMode
            Get
                Return m_TextRenderStyle
            End Get
            Set(ByVal value As Drawing2D.SmoothingMode)
                m_TextRenderStyle = value
            End Set
        End Property

        Public Overrides Sub Draw(ByVal g As System.Drawing.Graphics)
            Dim gContainer As System.Drawing.Drawing2D.GraphicsContainer
            Dim myMatrix As Drawing2D.Matrix
            gContainer = g.BeginContainer()
            myMatrix = g.Transform()
            If m_Rotation <> 0 Then
                myMatrix.RotateAt(m_Rotation, New PointF(X, Y), Drawing.Drawing2D.MatrixOrder.Append)
                g.Transform = myMatrix
            End If
            If Not Me.TextRenderStyle = -1 Then g.TextRenderingHint = Me.TextRenderStyle
            If Me.AutoSize Then
                Dim mySize As SizeF = g.MeasureString(m_Text, m_Font)
                Me.Width = Convert.ToInt32(mySize.Width)
                Me.Height = Convert.ToInt32(mySize.Height)
                g.DrawString(m_Text, m_Font, New SolidBrush(m_Color), X, Y)
            Else
                Dim rect As New System.Drawing.RectangleF(X, Y, Me.Width, Me.Height)
                g.DrawString(m_Text, m_Font, New SolidBrush(m_Color), rect)
            End If
            g.EndContainer(gContainer)
        End Sub

        Public Sub SetText(ByVal stext As String)
            m_Text = stext
        End Sub

    End Class

End Namespace