GDI+ Zeichnung wird extrem unscharf/unsauber

  • VB.NET
  • .NET (FX) 4.5–4.8

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von mrMo.

    GDI+ Zeichnung wird extrem unscharf/unsauber

    Hallo.

    Ich habe eine Klassenbibliothek, in der ich mir gerade selbst ein paar Controls am erstellen bin. Soweit so gut.
    In einer Windows-Forms Anwendung erbe ich die Controls aus der Klassenbibliothek (u.A. auch die Form).

    Jetzt sieht im Designer alles wirklich super aus - wenn ich das Programm starte
    jedoch nicht. Alles wirkt unscharf, schlecht gezeichnet. Selbst die "originalen" mit dem .Net Framework
    mitgelieferten Controls sehen auf der Form beim gestarteten Programm unscharf aus.


    Ich habe mir bereits einige Threads angesehen zu diesem Thema, denke jedoch, dass
    irgendwie mein Code noch optimierung benötigt.

    Kann mir da jemand was zu sagen?

    Mein Code:


    VB.NET-Quellcode

    1. Public Class SiriContainer : Inherits ContainerControl
    2. Private moveHeight As Integer = 38
    3. Private formCanMove As Boolean = False
    4. Private mouseX, mouseY As Integer
    5. Private overExit, overMin As Boolean
    6. Public Overrides Property Text() As String
    7. Get
    8. Return MyBase.Text
    9. End Get
    10. Set(value As String)
    11. MyBase.Text = value
    12. Invalidate()
    13. End Set
    14. End Property
    15. Sub New()
    16. SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or
    17. ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.SupportsTransparentBackColor Or ControlStyles.FixedHeight, True)
    18. MyBase.Update()
    19. Dock = DockStyle.Fill
    20. Font = New Font("Arial", 9, FontStyle.Bold)
    21. BackColor = Color.FromArgb(15, 15, 15)
    22. End Sub
    23. Protected Overrides Sub CreateHandle()
    24. MyBase.CreateHandle()
    25. FindForm.FormBorderStyle = FormBorderStyle.None
    26. If FindForm.TransparencyKey = Nothing Then FindForm.TransparencyKey = Color.Fuchsia
    27. End Sub
    28. Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
    29. MyBase.OnPaint(e)
    30. Dim G As Graphics = e.Graphics
    31. G.SmoothingMode = SmoothingMode.HighSpeed
    32. G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit
    33. G.Clear(FindForm.TransparencyKey)
    34. Dim slope As Integer = 8
    35. Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
    36. Dim mainPath As GraphicsPath = DrawIt.RoundRect(mainRect, slope)
    37. G.FillPath(New SolidBrush(BackColor), mainPath)
    38. G.DrawPath(New Pen(Color.FromArgb(30, 35, 45)), mainPath)
    39. G.FillPath(New SolidBrush(Color.FromArgb(30, 30, 40)), DrawIt.RoundRect(New Rectangle(0, 0, Width - 1, moveHeight - slope), slope))
    40. G.FillRectangle(New SolidBrush(Color.FromArgb(30, 30, 40)), New Rectangle(0, moveHeight - (slope * 2), Width - 1, slope * 2))
    41. G.DrawLine(New Pen(Color.FromArgb(60, 60, 60)), New Point(1, moveHeight), New Point(Width - 2, moveHeight))
    42. G.SmoothingMode = SmoothingMode.HighQuality
    43. Dim textX As Integer = 6
    44. Dim textY As Integer = CInt((moveHeight / 2) - (G.MeasureString(Text, Font).Height / 2) + 1)
    45. Dim textSize As SizeF = G.MeasureString(Text, Font)
    46. Dim textRect As New Rectangle(textX, textY, CInt(textSize.Width), CInt(textSize.Height))
    47. Dim textBrush As New LinearGradientBrush(textRect, Color.FromArgb(185, 190, 195), Color.FromArgb(125, 125, 125), 90.0F)
    48. G.DrawString(Text, Font, textBrush, New Point(textX, textY))
    49. If overExit Then
    50. G.DrawString("r", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(253, 96, 96)), New Point(Width - 27, 11))
    51. Else
    52. G.DrawString("r", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(205, 210, 215)), New Point(Width - 27, 11))
    53. End If
    54. If overMin Then
    55. G.DrawString("0", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(25, 100, 140)), New Point(Width - 47, 10))
    56. Else
    57. G.DrawString("0", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(205, 210, 215)), New Point(Width - 47, 10))
    58. End If
    59. End Sub
    60. Protected Overrides Sub OnMouseMove(e As System.Windows.Forms.MouseEventArgs)
    61. MyBase.OnMouseMove(e)
    62. If formCanMove Then
    63. FindForm.Location = New Point(MousePosition.X - mouseX, MousePosition.Y - mouseY)
    64. End If
    65. overExit = (e.Y > 11 AndAlso e.Y < 24) AndAlso (e.X > Width - 23 AndAlso e.X < Width - 10)
    66. overMin = (e.Y > 11 AndAlso e.Y < 24) AndAlso (e.X > Width - 44 AndAlso e.X < Width - 31)
    67. Invalidate()
    68. End Sub
    69. Protected Overrides Sub OnMouseDown(e As System.Windows.Forms.MouseEventArgs)
    70. MyBase.OnMouseDown(e)
    71. mouseX = e.X
    72. mouseY = e.Y
    73. If e.Y <= moveHeight AndAlso overExit = False AndAlso overMin = False Then formCanMove = True
    74. If overExit Then
    75. FindForm.Close()
    76. ElseIf overMin Then
    77. FindForm.WindowState = FormWindowState.Minimized
    78. overExit = False
    79. overMin = False
    80. Else
    81. Focus()
    82. End If
    83. Invalidate()
    84. End Sub
    85. Protected Overrides Sub OnMouseUp(e As System.Windows.Forms.MouseEventArgs)
    86. MyBase.OnMouseUp(e)
    87. formCanMove = False
    88. End Sub
    89. End Class
    Evtl. gleiches Problem wie hier gelöst: Komplette Form ist unscharf
    "Gib einem Mann einen Fisch und du ernährst ihn für einen Tag. Lehre einen Mann zu fischen und du ernährst ihn für sein Leben."

    Wie debugge ich richtig? => Debuggen, Fehler finden und beseitigen
    Wie man VisualStudio nutzt? => VisualStudio richtig nutzen