ASP.NET Drop Shadow Control#

I created this control to create dropshadows on dynamic text.  I also considered using the Drawing namespace to generate an image and stream it.  I breifly even used Microsoft's IE-only filter:dropshadow css attribute.  The staw that broke the camels back on that was the fact that this filter looks terrible on XP machines with ClearType enabled.  I found an article about using a span within a div and repeating your contents twice (essentially creating a copy of your text, oversetting it, and changing its color).  I used this concept to create the server control described below.

The DropShadow control acts like a panel in the sense that it contains controls and renders them within a <div> tag.  In addition to that, however, this control captures the text "output" by all it's child controls and contents and repeats it (without any HTML tags) in such a way that it acts as a drop shadow.

Static Text Code:
<ctl:DropShadow runat="server">Search</ctl:DropShadow>

Static Text Rendering:


Static Text Rendering (Magnified):



Dynamic Control Code:
<
ctl:DropShadow runat="server"><asp:LinkButton id="lbnDisposition" Text="Status" runat="server" /></ctl:DropShadow>

Dynamic Control Rendering:


Dynamic Control Rendering (Magnified):



Notice in the second (dynamic) example that the <a> tag created by the LinkButton control is not repeated in the shadow, but the text is.

Code:

Public Class DropShadow : Inherits WebControls.Panel
  Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
    writer.Write("<div style=""height:1px; display:inline; white-space:nowrap; " & _
      "font-weight:bold; position:relative; left:1px; top:1px; color:" & _
      GetHexCode(BackColor) & ";"">")

    'capture child control's output
    Dim result As New StringBuilder
    RenderChildren(New HtmlTextWriter(New IO.StringWriter(result)))
    Dim html As String = result.ToString()
    Dim rx As New Text.RegularExpressions.Regex( _
      "</?(\w+)(\s*\w*\s*=\s*(""[^""]*""|'[^']'|[^>]*))*|/?>", & _
      RegularExpressions.RegexOptions.Multiline)
    html = rx.Replace(html, "")
    writer.Write(html)

    writer.Write("<span style=""position:absolute; left:-1px; top:-1px; color:" & _ 
      GetHexCode(ForeColor) & "; width:100%;"">")
    RenderChildren(writer)
    writer.Write("</span>")

    writer.Write("</div>")
  End Sub

  Private Function GetHexCode(ByVal Color As System.Drawing.Color) As String
    Return "#" & Color.R.ToString("x2") & _
      Color.G.ToString("x2") & _
      Color.B.ToString("x2")
  End Function

  Public Sub New()
    'default colors
    Me.ForeColor = Drawing.Color.Black
    Me.BackColor = Drawing.Color.White
  End Sub
End Class
2/21/2006 1:57:51 PM (Eastern Standard Time, UTC-05:00) #    Comments [0]  |  Trackback
Tracked by:
"Fosamax Lawyer Fosamax Attorney" (Fosamax Lawyer Fosamax Attorney) [Trackback]
"ReNu Recall Lawyer" (ReNu MoistureLoc Recall Lawyer Attorney) [Trackback]
"renu recall" (moistureloc renu recall) [Trackback]
"Nice look" (Nice) [Trackback]
"Readed" (Jacob) [Trackback]

 

Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

All content © 2008, Jonathan Tower
On this page
This site
Calendar
<November 2008>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
Archives
Sitemap
Blogroll OPML
Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail