How to draw mixed text with .Net 2.0

Is there a way to draw a mixed format in .Net 2.0? I'm looking for something similar to

System.Drawing.Graphics.DrawString()

My problem with this method is that it allows you to use only one formatting style for all text. But I need to draw a text that has different format styles (for example, part of the text should be underlined, another part is bold, etc.).

Many thanks!
Oliver

+3
source share
2 answers

I take the answer directly from the WPF book in action - It seems you have 2 options:

  • . , , ( , ).

  • RTF. , , , RTF, , .

    /li >

, , RTF- ( RichTextBox), .NET 2.0 - WinForms. , ...: -)

/ ( ) .. , , ?

. :

GDI + - # Corner, GDI +: http://www.c-sharpcorner.com/uploadfile/mahesh/gdi_plus12092005070041am/gdi_plus.aspx p >

, , GDI + Bitmap/Image: http://ondotnet.com/pub/a/dotnet/2003/05/05/gdiplus.html

!

, , GDI + - . GDI + Pro.NET 2.0 Windows Forms # ( .) , WinForms, , GDI +.

+1

HTML , :

Private Sub DrawHTMLString(sHTML As String, rct As RectangleF, dpiX As Single, dpiY As Single, g As Graphics)
    DrawHTMLString(sHTML, rct.X, rct.Y, rct.Width, rct.Height, dpiX, dpiY, g)
End Sub

Private Sub DrawHTMLString(sHTML As String, x As Single, y As Single, width As Single, height As Single, dpiX As Single, dpiY As Single, g As Graphics)
    g.InterpolationMode = InterpolationMode.NearestNeighbor
    g.SmoothingMode = SmoothingMode.AntiAlias
    g.CompositingQuality = CompositingQuality.AssumeLinear
    g.TextRenderingHint = TextRenderingHint.AntiAlias

    g.DrawImage(DrawHTMLString(sHTML, width, height, dpiX, dpiY), x, y)
End Sub

Private Function DrawHTMLString(sHTML As String, width As Single, height As Single, dpiX As Single, dpiY As Single) As Bitmap
    Dim bmp As Bitmap = Nothing
    Dim doc As HtmlDocument = Nothing

    Using wb As New WebBrowser()
        wb.ScrollBarsEnabled = False
        wb.ScriptErrorsSuppressed = True
        wb.Navigate("about:blank")

        wb.Width = width : wb.Height = height

        doc = wb.Document.OpenNew(True)
        doc.Write(sHTML)

        bmp = New Bitmap(wb.Width, wb.Height, PixelFormat.Format32bppArgb)
        bmp.SetResolution(dpiX, dpiY)

        wb.DrawToBitmap(bmp, New Rectangle(0, 0, wb.Width, wb.Height))
    End Using

    Return bmp
End Function

(, VB.NET) , .

0

Source: https://habr.com/ru/post/1743820/


All Articles