Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class VerticalText : Inherits UserControl
Public Sub New()
With Me
.SuspendLayout()
.BackColor = Color.Transparent
.Cursor = Cursors.Hand
.Font = New Font("Verdana", 12, FontStyle.Regular, GraphicsUnit.Point)
.ForeColor = Color.GhostWhite
.Size = New Size(35, 170)
.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
.SetStyle(ControlStyles.Opaque, False)
.SetStyle(ControlStyles.OptimizedDoubleBuffer, False)
.SetStyle(ControlStyles.Selectable, True)
.ResumeLayout()
End With
End Sub
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim params As CreateParams = MyBase.CreateParams
params.ExStyle = &H20
Return params
End Get
End Property
Private Text0 As String = "Acción y Reacción"
<Category("Apariencia"), Description("Especifica el texto contenido por el control.")>
Public Property Texto As String
Get
Return Text0
End Get
Set(ByVal value As String)
Text0 = value
Me.Invalidate()
End Set
End Property
Private BGColor As Color = Color.DarkGoldenrod
<Category("Apariencia"), Description("Especifica el color de fondo del rectangulo del control.")>
Public Property ColorFondo() As Color
Get
Return BGCOlor
End Get
Set(ByVal value As Color)
BGCOlor = value
Me.Invalidate()
End Set
End Property
Private ColorOver As Color = Color.Gold
<Category("Apariencia"), Description("Especifica el color de fondo del rectangulo para el evento hover.")>
Public Property ColorHover() As Color
Get
Return ColorOver
End Get
Set(ByVal value As Color)
ColorOver = value
Me.Invalidate()
End Set
End Property
Private Bcolor As Color = Color.Goldenrod
<Category("Apariencia"), Description("Especifica el color del borde para el rectangulo del control.")>
Public Property ColorBorde() As Color
Get
Return Bcolor
End Get
Set(ByVal value As Color)
Bcolor = value
Me.Invalidate()
End Set
End Property
Private Sub ControlVertical(ByVal ColorTexto As Color, ByVal ColorFondo As Color, ByVal ColorBorde As Color)
Using g As Graphics = Me.CreateGraphics
Dim Formato As System.Drawing.StringFormat = New StringFormat(StringFormatFlags.DirectionVertical) ' <- Aquí la magia!!!!
Dim TextSize As SizeF = g.MeasureString(Text0, Me.Font)
Dim Pos As Point = New Point(Me.ClientRectangle.Width / 2 - TextSize.Height / 2,
Me.ClientRectangle.Height / 2 - TextSize.Width / 2)
g.FillRectangle(New SolidBrush(ColorFondo), New Rectangle(6, 3, TextSize.Height, TextSize.Width + 10))
g.DrawString(Text0, Me.Font, New SolidBrush(ColorTexto), Pos.X, Pos.Y, Formato)
g.DrawRectangle(New Pen(ColorBorde, 1), New Rectangle(6, 3, TextSize.Height, TextSize.Width + 10))
Formato.Dispose()
End Using
End Sub
Private Sub VerticalText_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter
ControlVertical(Me.ForeColor, ColorOver, Bcolor)
End Sub
Private Sub VerticalText_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
ControlVertical(Me.ForeColor, BGColor, Bcolor)
Me.Invalidate()
End Sub
Private Sub VerticalText_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
ControlVertical(Me.ForeColor, BGColor, Bcolor)
End Sub
End Class