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
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.
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
Re: VB.NET FormattedText Drawing
Thread moved from the 'VB.Net' forum to the 'WPF, WCF, WF' forum (thanks for letting us know jmcilhinney :thumb: )
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.
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