Path mit zwei Farben füllen

  • VB.NET

Es gibt 6 Antworten in diesem Thema. Der letzte Beitrag () ist von der_Kurt.

    Path mit zwei Farben füllen

    Hallo,

    wie kann man ein Path mit zwei Farben zeichnen? Also allgemein wäre das ja kein Problem, jedoch zeichne ich runde ecken. Undzwar so:

    VB.NET-Quellcode

    1. Private Function BorderRadius(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal radius As Integer) As GraphicsPath
    2. Dim gp As GraphicsPath = New GraphicsPath()
    3. gp.AddLine(x + radius, y, x + width - radius, y)
    4. gp.AddArc(x + width - radius, y, radius, radius, 270, 90)
    5. gp.AddLine(x + width, y + radius, x + width, y + height - radius)
    6. gp.AddArc(x + width - radius, y + height - radius, radius, radius, 0, 90)
    7. gp.AddLine(x + width - radius, y + height, x + radius, y + height)
    8. gp.AddArc(x, y + height - radius, radius, radius, 90, 90)
    9. gp.AddLine(x, y + height - radius, x, y + radius)
    10. gp.AddArc(x, y, radius, radius, 180, 90)
    11. gp.CloseFigure()
    12. 'gp.Dispose()
    13. Return gp
    14. End Function


    Gibt es ne Möglichkeit? Also ich will den Button szs. zu 50 % mit R(240)G(240)G(240) und weiss füllen.

    Grüße

    VB.NET-Quellcode

    1. Private Sub DrawBeam(g As Graphics)
    2. Dim p1 An New GraphicsPath()
    3. Dim p2 An New GraphicsPath()
    4. ' p1 und p2 befüllen
    5. g.DrawPath(Pens.Blue, p1)
    6. g.DrawPath(Pens.Yellow, p2)
    7. End Sub
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!

    VB.NET-Quellcode

    1. Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    2. FillMeinenGRPath(100, 100, 140, 50, 45)
    3. End Sub
    4. Sub FillMeinenGRPath(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal radius As Integer)
    5. Dim rect As New Rectangle(x, y, width, height)
    6. Using gradientBrush As New LinearGradientBrush(rect, Color.Gray, Color.White, LinearGradientMode.Horizontal)
    7. Using f = Me.CreateGraphics
    8. f.FillPath(gradientBrush,
    9. BorderRadius(x, y, width, height, radius))
    10. End Using
    11. End Using
    12. End Sub


    Ich hoffe, du meinst sowas (selbstverständlich read&learn, nicht copy&paste).