Problem mit FastColoredTextBox

  • VB.NET

Es gibt 22 Antworten in diesem Thema. Der letzte Beitrag () ist von nafets3646.

    Ich möchte, dass wenn jemand irgendwelchen Schrott hinschreibt, dass es so aussieht:

    Mir geht es also um die blaue Linie.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „nafets3646“ ()

    Soo, ich habe es jetzt geschafft, einen Style zu schreiben, welcher mir die gewellte Linie wie gewollt zeichnet, jetzt muss ich nur noch wissen, wie man den Style auf eine ganz bestimmte Position im Text anwenden kann.
    UnderlinedStyle

    VB.NET-Quellcode

    1. Friend Class UnderlinedStyle
    2. Inherits Style
    3. Public Property ForeBrush As Brush
    4. Public Property BackgroundBrush As Brush
    5. Public Property FontStyle As FontStyle
    6. Public Property ExcludeWhitespaceAtStart As Boolean = True
    7. Public Property ExcludeCommentsAndWhitespaceAtEnd As Boolean = True
    8. Public Property WaveColor As Color = Color.Blue
    9. Private WavePens As New List(Of IEnumerable(Of Tuple(Of Single(), Integer, Integer))) From { _
    10. {{Tuple.Create({1.0!, 5.0!}, 255, 0), Tuple.Create({1.0!, 3.0!, 1.0!, 1.0!}, 128, 1)}}, _
    11. {{Tuple.Create({2.0!, 1.0!}, 128, 1)}}, _
    12. {{Tuple.Create({1.0!, 5.0!}, 255, 3), Tuple.Create({1.0!, 1.0!, 1.0!, 3.0!}, 128, 2)}} _
    13. }
    14. Public Overrides Sub Draw(gr As Graphics, position As Point, range As Range)
    15. If BackgroundBrush IsNot Nothing Then
    16. gr.FillRectangle(BackgroundBrush, position.X, position.Y, (range.[End].iChar - range.Start.iChar) * range.tb.CharWidth, range.tb.CharHeight)
    17. End If
    18. Dim Y As Single = position.Y
    19. Dim X As Single = position.X
    20. Dim Width As Single = (range.End.iChar - range.Start.iChar + 4) * range.tb.CharWidth
    21. Dim OffsetLeft As Single = 0
    22. Dim OffsetRight As Single = 0
    23. If Me.ExcludeWhitespaceAtStart Then 'Whitespace am Anfang erkennen
    24. For Each c In range.Chars
    25. If Char.IsWhiteSpace(c.c) Then
    26. OffsetLeft += range.tb.CharWidth
    27. Else
    28. Exit For
    29. End If
    30. Next
    31. End If
    32. If Me.ExcludeCommentsAndWhitespaceAtEnd Then 'Kommentare und Whitespace am Ende erkennen
    33. Dim CommentDetected As Boolean = False
    34. For X1 As Integer = 0 To range.Chars.Count - 1
    35. If (Not CommentDetected) AndAlso range.Chars(X1).c = "'"c Then
    36. CommentDetected = True
    37. For X2 As Integer = X1 - 1 To 0 Step -1
    38. If Char.IsWhiteSpace(range.Chars(X2).c) Then
    39. OffsetRight += range.tb.CharWidth
    40. Else
    41. Exit For
    42. End If
    43. Next
    44. End If
    45. If CommentDetected Then OffsetRight += range.tb.CharWidth
    46. Next
    47. If Not CommentDetected Then
    48. For X1 As Integer = range.Chars.Count - 1 To 0 Step -1
    49. If Char.IsWhiteSpace(range.Chars(X1).c) Then
    50. OffsetRight += range.tb.CharWidth
    51. Else
    52. Exit For
    53. End If
    54. Next
    55. End If
    56. End If
    57. 'Linie zeichnen
    58. If Width - OffsetLeft - OffsetRight - range.tb.CharWidth * 3 > 0 AndAlso Not range.Text.StartsWith("'"c) Then
    59. For Y1 As Integer = 0 To 2
    60. For Each t In WavePens(Y1)
    61. gr.DrawLine(New Pen(Color.FromArgb(t.Item2, WaveColor)) With {.DashPattern = t.Item1}, New PointF(X + t.Item3 + OffsetLeft, Y + Y1 + range.tb.CharHeight), New PointF(Width - OffsetRight, Y + Y1 + range.tb.CharHeight))
    62. Next
    63. Next
    64. End If
    65. End Sub
    66. End Class