Results 1 to 6 of 6

Thread: VB.NET FormattedText Drawing

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    220

    VB.NET FormattedText Drawing

    Hi, I am looking for a code to do FormattedText drawing in vb.net. I tried the vb code that uses Overrriding the OnRender Function and the compiler just gave a blank page. If you know of a good link or just a short example on vb.net FormattedText please help. Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB.NET FormattedText Drawing

    If you're talking about OnRender then you're talking about WPF. This site has a forum dedicated to WPF, so I've asked the mods to move this thread there.

    Also, you might consider posting the code that didn't work. If we see what you did then we can see what you did wrong. It could be something very small, but we'll never know if we don't see it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    220

    Re: VB.NET FormattedText Drawing

    This is the code I used. Yes, this is Runtime coding in WPF. I always get a blank page when compiling this code. What is wrong? I use VB 2008 Express.
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

    Protected Overrides Sub OnRender(ByVal drawingContext As DrawingContext)
    Dim testString As String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor"

    ' Create the initial formatted text string.
    Dim formattedText As New FormattedText(testString, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, New Typeface("Verdana"), 32, Brushes.Black)

    ' Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
    formattedText.MaxTextWidth = 300
    formattedText.MaxTextHeight = 240

    ' Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
    ' The font size is calculated in terms of points -- not as device-independent pixels.
    formattedText.SetFontSize(36 * (96.0 / 72.0), 0, 5)

    ' Use a Bold font weight beginning at the 6th character and continuing for 11 characters.
    formattedText.SetFontWeight(FontWeights.Bold, 6, 11)

    ' Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
    formattedText.SetForegroundBrush(New LinearGradientBrush(Colors.Orange, Colors.Teal, 90.0), 6, 11)

    ' Use an Italic font style beginning at the 28th character and continuing for 28 characters.
    formattedText.SetFontStyle(FontStyles.Italic, 28, 28)

    ' Draw the formatted text string to the DrawingContext of the control.
    drawingContext.DrawText(formattedText, New Point(10, 0))
    End Sub

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: VB.NET FormattedText Drawing

    Thread moved from the 'VB.Net' forum to the 'WPF, WCF, WF' forum (thanks for letting us know jmcilhinney )

  5. #5
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: VB.NET FormattedText Drawing

    Is there a reason you're not doing the above with a FlowDocument, or set of Runs and piping it to standard controls? I've never actually come across a reason to drop down to OnRender in WPF so don't have anything particularly helpful off the top of my head to say why that approach isn't working.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    220

    Re: VB.NET FormattedText Drawing

    I bumped onto this Drawing Formatted Text code when I was looking for an WPF alternative to the DrawString Method (GDI). However, when I tried it it failed. I am not that familiar with FlowDocuments. My thought was that the OnRender() is more suited for Formatted text than FlowDocument. I would welcome any good advice as to what is best for Formatted strings in WPF. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width