GDI + - Form Rand erstellen

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Vb K1ng.

    GDI + - Form Rand erstellen

    Hej liebe Community-User,
    Ich habe meine Form aberundet und möchte nun einen Rand zeichnen (innere Rand).
    Ich weiß, dass dies mit drawArc möglich ist, womit ich mich irgendwie überhaupt nicht auskenne.

    DrawArc hat zwei zusätzliche Parameter die als ° angegeben werden.

    Kennt sich vielleicht jemand damit aus ?

    Wäre auch für Links und Codeschnipsel dankbar !

    mfg,
    VB K1ng
    Vielen Dank EiPott!



    Falls jemand das gleiche Problem hat:

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Sub DrawRoundedRectangle(ByVal g As Graphics, _
    2. ByVal r As Rectangle, _
    3. ByVal radius As Single, _
    4. ByVal borderColor As Color)
    5. ' GraphicsPath erstellen
    6. Dim path As GraphicsPath = RectanglePath(r, radius)
    7. ' Rechteck mit angerundeten Ecken zeichnen
    8. g.DrawPath(New Pen(borderColor, 10), path)
    9. ' Ressourcen freigeben
    10. path.Dispose()
    11. End Sub
    12. Private Function RectanglePath(ByVal r As RectangleF, _
    13. ByVal radius As Single) As GraphicsPath
    14. ' Neues GraphicsPath-Objekt erstellen
    15. Dim path As New GraphicsPath
    16. Dim d As Single = 2 * radius
    17. ' Zusammensetzen des GraphicsPath
    18. With path
    19. If radius < 1 Then
    20. ' keine abgerundeten Ecken
    21. .AddRectangle(r)
    22. Else
    23. ' Linien und Bögen erstellen
    24. .AddLine(r.X + radius, r.Y, r.X + r.Width - d, r.Y)
    25. .AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90)
    26. .AddLine(r.X + r.Width, r.Y + radius, r.X + r.Width, r.Y + r.Height - d)
    27. .AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90)
    28. .AddLine(r.X + r.Width - d, r.Y + r.Height, r.X + radius, r.Y + r.Height)
    29. .AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90)
    30. .AddLine(r.X, r.Y + r.Height - d, r.X, r.Y + radius)
    31. .AddArc(r.X, r.Y, d, d, 180, 90)
    32. End If
    33. .CloseFigure()
    34. End With
    35. Return (path)
    36. End Function
    37. Private Sub form_main_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    38. ' Rechteck -Größe
    39. Dim r As Rectangle
    40. With Me
    41. r = New Rectangle(0, 0, .Width - 1, .Height - 1)
    42. End With
    43. ' Rundung in Pixel
    44. Dim radius As Single = 20
    45. ' abgerundetes Rechteck mit Farbverlauf zeichnen
    46. DrawRoundedRectangle(e.Graphics, r, radius, Color.RoyalBlue)
    47. End Sub