기타 [vb.net] 문자 회전해서 그리기(drawstring rotate text)
페이지 정보
본문
Imports System.Drawing.Drawing2D
Public Class Form1
Dim Label1 As myLabel
Dim Label2 As myLabel
Dim Label3 As myLabel
Dim myLabels As New List(Of myLabel)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Label1 = New myLabel("Label1", New Point(50, 50))
myLabels.Add(Label1)
Label2 = New myLabel("Label2", New Point(100, 100), 45)
myLabels.Add(Label2)
Label3 = New myLabel("Label3", New Point(100, 100), -45, New Font("Arial", 18), Color.Blue)
myLabels.Add(Label3)
End Sub
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
For Each Lbl As myLabel In myLabels
Lbl.Draw(e.Graphics)
Next
End Sub
End Class
Public Class myLabel
Public Property Text As String
Public Property Location As Point
Public Property Angle As Integer
Public Property Font As Font
Public Property ForeColour As Color
Public Sub New(Text As String, Location As Point)
Me.New(Text, Location, 0, New Font("Arial", 10), Color.Black)
End Sub
Public Sub New(Text As String, Location As Point, Angle As Integer)
Me.New(Text, Location, Angle, New Font("Arial", 10), Color.Black)
End Sub
Public Sub New(Text As String, Location As Point, Angle As Integer, Font As Font)
Me.New(Text, Location, Angle, Font, Color.Black)
End Sub
Public Sub New(Text As String, Location As Point, Angle As Integer, Font As Font, ForeColour As Color)
Me.Text = Text
Me.Location = Location
Me.Angle = Angle
Me.Font = Font
Me.ForeColour = ForeColour
End Sub
Public Sub Draw(g As Graphics)
Dim State As GraphicsState = g.Save
g.TranslateTransform(Location.X, Location.Y)
g.RotateTransform(Angle)
Using Brsh As New SolidBrush(ForeColour)
g.DrawString(Text, Font, Brsh, New Point(0, 0))
End Using
g.Restore(State)
End Sub
End Class
- 이전글[vb.net] DataTable(데이터 테이블)에서 DataRow(행) 인덱스 찾기 및 가져 오기 19.09.18
- 다음글[vb.net] 경로 또는 리소스(Resources) ttf 파일 폰트 변환 19.08.04
댓글목록
등록된 댓글이 없습니다.