Eine runde PictureBox geht das?

  • VB.NET

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

    das geht ja, mit folgender sub:

    VB.NET-Quellcode

    1. Sub abrunden(ByVal was As Object, _
    2. ByVal x As Integer, ByVal y As Integer, _
    3. ByVal width As Integer, ByVal height As Integer, _
    4. ByVal radius As Integer)
    5. Dim gp As System.Drawing.Drawing2D.GraphicsPath = _
    6. New System.Drawing.Drawing2D.GraphicsPath()
    7. gp.AddLine(x + radius, y, x + width - radius, y)
    8. gp.AddArc(x + width - radius, y, radius, radius, 270, 90)
    9. gp.AddLine(x + width, y + radius, x + width, y + height - radius)
    10. gp.AddArc(x + width - radius, y + height - radius, radius, radius, 0, 90)
    11. gp.AddLine(x + width - radius, y + height, x + radius, y + height)
    12. gp.AddArc(x, y + height - radius, radius, radius, 90, 90)
    13. gp.AddLine(x, y + height - radius, x, y + radius)
    14. gp.AddArc(x, y, radius, radius, 180, 90)
    15. gp.CloseFigure()
    16. was.region = New System.Drawing.Region(gp)
    17. gp.Dispose()
    18. End Sub


    Und im button oder im form load event:

    VB.NET-Quellcode

    1. abrunden(PictureBox1, 0, 0, PictureBox1.Width, PictureBox1.Height, 120)


    Oder per GDI:

    VB.NET-Quellcode

    1. Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    2. Dim g As Graphics = Me.CreateGraphics
    3. Dim rect As New Rectangle(100, 100, 100, 100)
    4. g.DrawEllipse(Pens.BlanchedAlmond, rect)
    5. End Sub

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

    Wie Scream schon geschrieben hat musst du den Code in der Mitte dorthin machen wo das abgerundet werden soll(Sinnvoll ist halt das Load Event). Für die Picbox gameBall würde das so aussehen:

    VB.NET-Quellcode

    1. abrunden(gameBall, 0, 0, gameBall.Width, gameBall.Height, 120)


    Mfg
    Firestorm
    Für einen runden Ball in dem Sinne geht es doch viel einfacher..:

    VB.NET-Quellcode

    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2. abrunden(PictureBox1, 0, 0, 140)
    3. End Sub
    4. Sub abrunden(ByVal YourPb As Object, ByVal Posx As Integer, ByVal Posy As Integer, ByVal diameter As Integer)
    5. Using gp As New System.Drawing.Drawing2D.GraphicsPath()
    6. gp.AddEllipse(Posx, Posy, diameter, diameter)
    7. YourPb.region = New System.Drawing.Region(gp)
    8. End Using
    9. End Sub


    gruss Mono
    Das ist meine Signatur und sie wird wunderbar sein!