RotatedTextImage Control
Life With Nate
Nate's Poetry Page
Resume (PDF)
Nate's Code
ASP.NET 2.0/3.5
ButtonExtensions
ConditionalRequiredTextValidator
CSSImageMap
CustomStyle
DateTimePicker
DateTimePickerTemplated
LengthValidator
RestrictInputTextBox
RestrictInputValidator
Rollovers
RotatedTextHandler
RotatedTextImage
Rotators
SelectedCountValidator
SlideIntoView
StatesDropDownList
UniqueValueValidatorBase
VB.NET 2.0/3.5
Just For Fun
Windows Phone 7
Description
The RotatedTextImage control inherits from the System.Web.UI.WebControls.Image and is used to create an image that uses the
RotatedTextHandler
as it's source to generate an image of rotated text.
Example
Below are several examples of the RotatedTextImage control. You can click each image to see the URL that each image came from.
BackgroundStyle:
Transparent
BackgroundStyle:
TextOnly
BackgroundStyle:
Complete
Rotation: 30
Rotation: 90
Rotation: 150
Rotation: 230
Rotation: 270
Rotation: 300
Properties & Methods
RotatedTextImage
The RotatedTextImage control inherits from System.Web.UI.WebControls.Image and is used to create an image that uses the
RotatedTextHandler
as it's source to generate an image of rotated text.
Rotation
- A Double specifying the angle, in degrees, that the text is to be rotated
Text
- A String specifying the text to be rotated
FontColor
- The System.Drawing.Color of the text
BackgroundStyle
- A member of the
NathanSokalski.RotatedTextHandler.BackgroundStyle enumeration
specifying what part of the background should be colored
Background
- The System.Drawing.Color used if TextOnly or Complete is selected for the BackgroundStyle property
Bold
- A Boolean value specifying whether the text is bold
Italic
- A Boolean value specifying whether the text is italicized
Strikeout
- A Boolean value specifying whether the text is strikeout
Underline
- A Boolean value specifying whether the text is underlined
FontName
- A String specifying the name of the font used for the text
Size
- A Single specifying the size of the text
GetImageUrl(ByVal rotangle As Double, ByVal txt As String, ByVal fntcolor As System.Drawing.Color, ByVal bgstyle As NathanSokalski.RotatedTextHandler.BackgroundStyle, ByVal bgcolor As System.Drawing.Color, ByVal bold As Boolean, ByVal italic As Boolean, ByVal strikeout As Boolean, ByVal underline As Boolean, ByVal fntname As String, ByVal fntsize As Single) As String
GetImageUrl(ByVal rotangle As Double, ByVal txt As String, ByVal fntcolor As System.Drawing.Color, ByVal bgstyle As NathanSokalski.RotatedTextHandler.BackgroundStyle, ByVal bgcolor As System.Drawing.Color, ByVal fntstyle As System.Drawing.FontStyle, ByVal fntname As String, ByVal fntsize As Single) As String
The GetImageUrl function is a shared function that can be used to generate the URL that will generate the gif file for the rotated text
rotangle
- A Double specifying the angle, in degrees, that the text is to be rotated
txt
- A String specifying the text to be rotated
fntcolor
- The System.Drawing.Color of the text
bgstyle
- A member of the NathanSokalski.RotatedTextHandler.BackgroundStyle enumeration specifying what part of the background should be colored
bgcolor
- The System.Drawing.Color used if TextOnly or Complete is selected for the BackgroundStyle property
bold
- A Boolean value specifying whether the text is bold
italic
- A Boolean value specifying whether the text is italicized
strikeout
- A Boolean value specifying whether the text is strikeout
underline
- A Boolean value specifying whether the text is underlined
fntstyle
- A System.Drawing.FontStyle used to specify whether the text should be bold, italic, strikeout, and/or underlined
fntname
- A String specifying the name of the font used for the text
fntsize
- A Single specifying the size of the text
Source Code
RotatedTextImage.vb:
Namespace NathanSokalski <System.Drawing.ToolboxBitmap(GetType(ToolboxIcons), "RotatedTextImage.bmp")> _ Public Class RotatedTextImage : Inherits System.Web.UI.WebControls.Image 'The following code must be included in a Web Application's Web.config in order to use the RotatedTextHandler, which is used by the RotatedTextImage: '<configuration> ' <system.web> ' <httpHandlers> ' <add path="*/RotatedTextHandler.ashx" verb="*" type="NathanSokalski.RotatedTextHandler,NathanSokalski" validate="false"/> ' </httpHandlers> ' </system.web> '</configuration> Private _rotation As Double = 0 Private _text As String = String.Empty Private _fontcolor As System.Drawing.Color = Drawing.Color.Black Private _backgroundstyle As NathanSokalski.RotatedTextHandler.BackgroundStyle = NathanSokalski.RotatedTextHandler.BackgroundStyle.Transparent Private _background As System.Drawing.Color = Drawing.Color.White Private _fontstyle As New System.Drawing.FontStyle Private _fontname As String = "Arial" Private _size As Single = 24 <DefaultValue(0), _ Description("The number of degrees clockwise the text is rotated")> _ Public Property Rotation() As Double Get Return Me._rotation End Get Set(ByVal value As Double) Me._rotation = value End Set End Property <Description("The text use to generate the image")> Public Property Text() As String Get Return Me._text End Get Set(ByVal value As String) Me._text = value End Set End Property <DefaultValue("Black"), _ Description("The color used for the text")> _ Public Property FontColor() As System.Drawing.Color Get Return Me._fontcolor End Get Set(ByVal value As System.Drawing.Color) Me._fontcolor = value End Set End Property <DefaultValue("Transparent"), _ Description("A member of the NathanSokalski.RotatedTextHandler.BackgroundStyle enumeration specifying what part of the background should be colored")> _ Public Property BackgroundStyle() As NathanSokalski.RotatedTextHandler.BackgroundStyle Get Return Me._backgroundstyle End Get Set(ByVal value As NathanSokalski.RotatedTextHandler.BackgroundStyle) Me._backgroundstyle = value End Set End Property <DefaultValue("White"), _ Description("The background color used when the text has a background")> _ Public Property Background() As System.Drawing.Color Get Return Me._background End Get Set(ByVal value As System.Drawing.Color) Me._background = value End Set End Property <DefaultValue(False), _ Description("A Boolean value specifying whether the text is bold")> _ Public Property Bold() As Boolean Get Return (Me._fontstyle And System.Drawing.FontStyle.Bold) = System.Drawing.FontStyle.Bold End Get Set(ByVal value As Boolean) If value Then Me._fontstyle = Me._fontstyle Or System.Drawing.FontStyle.Bold Else Me._fontstyle = Me._fontstyle And Not System.Drawing.FontStyle.Bold End Set End Property <DefaultValue(False), _ Description("A Boolean value specifying whether the text is italic")> _ Public Property Italic() As Boolean Get Return (Me._fontstyle And System.Drawing.FontStyle.Italic) = System.Drawing.FontStyle.Italic End Get Set(ByVal value As Boolean) If value Then Me._fontstyle = Me._fontstyle Or System.Drawing.FontStyle.Italic Else Me._fontstyle = Me._fontstyle And Not System.Drawing.FontStyle.Italic End Set End Property <DefaultValue(False), _ Description("A Boolean value specifying whether the text is strikeout")> _ Public Property Strikeout() As Boolean Get Return (Me._fontstyle And System.Drawing.FontStyle.Strikeout) = System.Drawing.FontStyle.Strikeout End Get Set(ByVal value As Boolean) If value Then Me._fontstyle = Me._fontstyle Or System.Drawing.FontStyle.Strikeout Else Me._fontstyle = Me._fontstyle And Not System.Drawing.FontStyle.Strikeout End Set End Property <DefaultValue(False), _ Description("A Boolean value specifying whether the text is underlined")> _ Public Property Underline() As Boolean Get Return (Me._fontstyle And System.Drawing.FontStyle.Underline) = System.Drawing.FontStyle.Underline End Get Set(ByVal value As Boolean) If value Then Me._fontstyle = Me._fontstyle Or System.Drawing.FontStyle.Underline Else Me._fontstyle = Me._fontstyle And Not System.Drawing.FontStyle.Underline End Set End Property <DefaultValue("Arial"), _ Description("The name of the font used to generate the image")> _ Public Property FontName() As String Get Return Me._fontname End Get Set(ByVal value As String) Me._fontname = value End Set End Property <DefaultValue(24), _ Description("The size of the text")> _ Public Property Size() As Single Get Return Me._size End Get Set(ByVal value As Single) Me._size = value End Set End Property <Browsable(False)> Public Overrides Property ImageUrl() As String Get Return MyBase.ImageUrl End Get Set(ByVal value As String) MyBase.ImageUrl = value End Set End Property Private Sub RotatedTextImage_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender If Not Me.Page.ClientScript.IsClientScriptBlockRegistered("RotatedTextImagePreload") Then Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "RotatedTextImagePreload", "var RotatedTextImagePreload=new Image();", True) Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), String.Concat("RotatedTextImagePreload_", Me.ClientID), String.Format("RotatedTextImagePreload.src='{0}';", RotatedTextImage.GetImageUrl(Me._rotation, Me._text, Me._fontcolor, Me._backgroundstyle, Me._background, Me._fontstyle, Me._fontname, Me._size)), True) End Sub Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter) Me.ImageUrl = RotatedTextImage.GetImageUrl(Me._rotation, Me._text, Me._fontcolor, Me._backgroundstyle, Me._background, Me._fontstyle, Me._fontname, Me._size) MyBase.Render(writer) End Sub Public Shared Function GetImageUrl(ByVal rotangle As Double, ByVal txt As String, ByVal fntcolor As System.Drawing.Color, ByVal bgstyle As NathanSokalski.RotatedTextHandler.BackgroundStyle, ByVal bgcolor As System.Drawing.Color, ByVal bold As Boolean, ByVal italic As Boolean, ByVal strikeout As Boolean, ByVal underline As Boolean, ByVal fntname As String, ByVal fntsize As Single) As String Dim imgurl As New System.Collections.Generic.List(Of String) Dim tempstyle As New System.Drawing.FontStyle If bold Then tempstyle = tempstyle Or System.Drawing.FontStyle.Bold If italic Then tempstyle = tempstyle Or System.Drawing.FontStyle.Italic If strikeout Then tempstyle = tempstyle Or System.Drawing.FontStyle.Strikeout If underline Then tempstyle = tempstyle Or System.Drawing.FontStyle.Underline Return NathanSokalski.RotatedTextImage.GetImageUrl(rotangle, txt, fntcolor, bgstyle, bgcolor, tempstyle, fntname, fntsize) End Function Public Shared Function GetImageUrl(ByVal rotangle As Double, ByVal txt As String, ByVal fntcolor As System.Drawing.Color, ByVal bgstyle As NathanSokalski.RotatedTextHandler.BackgroundStyle, ByVal bgcolor As System.Drawing.Color, ByVal fntstyle As System.Drawing.FontStyle, ByVal fntname As String, ByVal fntsize As Single) As String Dim imgurl As New System.Collections.Generic.List(Of String) imgurl.Add(String.Format("Rotation={0}", rotangle)) imgurl.Add(String.Format("Text={0}", HttpContext.Current.Server.UrlEncode(txt))) imgurl.Add(String.Format("FontColor={0}", HttpContext.Current.Server.UrlEncode(System.Drawing.ColorTranslator.ToHtml(fntcolor)))) imgurl.Add(String.Format("BackgroundStyle={0}", CByte(bgstyle))) If bgstyle <> NathanSokalski.RotatedTextHandler.BackgroundStyle.Transparent Then imgurl.Add(String.Format("Background={0}", HttpContext.Current.Server.UrlEncode(System.Drawing.ColorTranslator.ToHtml(bgcolor)))) imgurl.Add(String.Format("FontStyle={0}", CInt(fntstyle))) imgurl.Add(String.Format("FontName={0}", HttpContext.Current.Server.UrlEncode(fntname))) imgurl.Add(String.Format("Size={0}", fntsize)) Return String.Format("RotatedTextHandler.ashx?{0}", String.Join("&", imgurl.ToArray())) End Function End Class End Namespace
Remarks
Because the RotatedTextImage control uses the
RotatedTextHandler
class to generate the gif file, you will need to download that as well in order to use the RotatedTextImage control in your site.