Apply shadow to html formatted label

7 posts, 2 answers
  1. Bob
    Bob avatar
    7 posts
    Member since:
    Dec 2011

    Posted 02 May 2012 Link to this post

    Is it possible to apply a shadow to text that you have adjusted using html. It seems that I can apply a shadow to text that has not been changed via html. But, If I make size, color, etc changes to text in a label, I cannot successfully apply a label. Here is what I have tried, without success.

    lblDateTime.Text = "<html>" & Format(CStr(DateTime.Now), "Long Date") & "<br><font=Arial Black><size=34><color=" & darkNight.ToArgb & ">" & Format(CStr(DateTime.Now), "Short time")
     
            Dim primitive As TextPrimitive = DirectCast(Me.lblDateTime.RootElement.Children(0).Children(2).Children(1), TextPrimitive)
            primitive.Shadow = New Telerik.WinControls.Paint.ShadowSettings(New Point(2, 2), Color.Red)

    Any help would be appreciated.
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 02 May 2012 Link to this post

    Hi Bob, 

    As far as I'm aware, the HTML rendering replaces the properties of those of the Primitive. You can see for example what happens if you set. 
    primitive.DisableHTMLRendering = True

    Regards, 
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 02 May 2012 Link to this post

    However, why not just format the font via the primitive rather than via HTML. 

    E.g

    primitive.DisableHTMLRendering = True
    primitive.Font = New Font("Arial", 34)
    primitive.ForeColor = Color.Black
    primitive.Shadow = New Telerik.WinControls.Paint.ShadowSettings(New Point(2, 2), Color.Red)
    lblDateTime.Text = Format(CStr(DateTime.Now), "Long Date") & Format(CStr(DateTime.Now), "Short time")

    Hope this helps
    Richard
  5. Bob
    Bob avatar
    7 posts
    Member since:
    Dec 2011

    Posted 02 May 2012 Link to this post

    Thanks for your response. The biggest reason that I was rendering via html was that the label contains two different fonts. The date is displayed smaller and then the time in a larger font. That way I could use a single label, instead of 2. I actually have several places where this is the case. Using a single label helps with arrangement and docking, which is always helpful. Another example is in a RadRotator, in which I've added a label item. For appearance sake, there are font, boldness and other changes in the displayed text, but again, it appears that I can't add a shadow. 

    I could break the date and time label into 2 labels and apply changes through the primitive, but was just hoping there was a way to render text, with html AND apply a shadow.

    Thanks again for your input.
  6. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 02 May 2012 Link to this post

    Hi Bob, 

    I may be mistaken, but I'm pretty sure that's the way you'd have to do it as HTML rendered text overrides the primitives properties. 
    I guess you could also build your own user control with the two labels inside that are rendered as you require to act as one control also? 
    Regards, 
    Richard
  7. Bob
    Bob avatar
    7 posts
    Member since:
    Dec 2011

    Posted 02 May 2012 Link to this post

    Ok. Thanks Richard. That provides some clarity.
  8. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 07 May 2012 Link to this post

    Hello Bob,

    Thank you for writing.

    I just want to confirm Richard's words that the HTML-like Text Formatting does not support text shadows.

    Do not hesitate to contact us if you have other questions.

    All the best,
    Peter
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready