Home All Groups Group Topic Archive Search About

RE: Rectangle with rounded corners

Author
2 Jun 2009 8:36 PM
Tomas Mattsson
I just want to show how I have shaped the corners of a form without any lines drawn:

Imports System.Drawing.Drawing2D

and first in the .Load event of the form

Dim p As New GraphicsPath

p.StartFigure()

'Upper left corner
p.AddArc(New Rectangle(0, 0, 20, 20), 180, 90)

'Upper right corner
p.AddArc(New Rectangle(Me.Width - 20, 0, 20, 20), 270, 90)

'Lower right corner
p.AddArc(New Rectangle(Me.Width - 20, Me.Height - 20, 20, 20), 0, 90)

'Lower left corner
p.AddArc(New Rectangle(0, Me.Height - 20, 20, 20), 90, 90)

p.CloseFigure()

Me.Region = New Region(p)

p.Dispose()

Me.Location = New Point(200, 200)

Note that I have changed the starting angle of the arc from -90 to 270 for Upper right corner. From http://www.developmentnow.com/g/38_2005_1_0_0_41861/Rectangle-with-rounded-corners.htm Posted via DevelopmentNow.com Groups http://www.developmentnow.com/g/

Author
2 Jun 2009 9:44 PM
gillardg
what about that
work also on controls but i have not yet tested all



Public Sub RoundCoin(ByVal radius As Integer, ByVal ctrl As Object)
        Dim frmToRnd As Object = ctrl
        Dim regionRects(radius * 2 + 2) As System.Drawing.Rectangle
        Dim circle As New Bitmap(radius * 2, radius * 2)
        Dim g As System.Drawing.Graphics =
System.Drawing.Graphics.FromImage(circle)
        g.Clear(Color.White)
        g.FillEllipse(Brushes.Black, 0, 0, circle.Width, circle.Height)
        Dim col As Integer = 0
        For row As Integer = 0 To radius - 1
            For col = 0 To radius - 1
                If circle.GetPixel(col, row) <>
System.Drawing.Color.FromArgb(255, 255, 255, 255) Then Exit For
            Next
            regionRects(row * 2) = New System.Drawing.Rectangle(col, row,
frmToRnd.Width - 2 * col, 1)
            regionRects(row * 2 + 1) = New System.Drawing.Rectangle(col,
frmToRnd.Height - row - 1, frmToRnd.Width - 2 * col, 1)
        Next
        regionRects(radius * 2 + 2) = New System.Drawing.Rectangle(0,
radius, frmToRnd.Width, frmToRnd.Height - circle.Height)
        Dim myPath As New Drawing2D.GraphicsPath
        myPath.AddRectangles(regionRects)
        frmToRnd.Region = New Region(myPath)

    End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

        For Each ctl As Control In Me.Controls
            Try
                RoundCoin(10, ctl)
            Catch ex As Exception

            End Try
        Next
        RoundCoin(20, Me)
        Button1.FlatStyle = FlatStyle.Popup
        TextBox1.BorderStyle = BorderStyle.None
        RichTextBox1.BorderStyle = BorderStyle.None
        MonthCalendar1.FirstDayOfWeek=Day.Monday
    End Sub



"Tomas Mattsson" <nospam@developmentnow.com> a écrit dans le message de
groupe de discussion :
d9b42ccd-c533-4031-87af-afcf0f5fd***@developmentnow.com...
Show quoteHide quote
> I just want to show how I have shaped the corners of a form without any
> lines drawn:
>
> Imports System.Drawing.Drawing2D
>
> and first in the .Load event of the form
>
> Dim p As New GraphicsPath
>
> p.StartFigure()
>
> 'Upper left corner
> p.AddArc(New Rectangle(0, 0, 20, 20), 180, 90)
>
> 'Upper right corner
> p.AddArc(New Rectangle(Me.Width - 20, 0, 20, 20), 270, 90)
>
> 'Lower right corner
> p.AddArc(New Rectangle(Me.Width - 20, Me.Height - 20, 20, 20), 0, 90)
>
> 'Lower left corner
> p.AddArc(New Rectangle(0, Me.Height - 20, 20, 20), 90, 90)
>
> p.CloseFigure()
>
> Me.Region = New Region(p)
>
> p.Dispose()
>
> Me.Location = New Point(200, 200)
>
> Note that I have changed the starting angle of the arc from -90 to 270 for
> Upper right corner.
>
> From
> http://www.developmentnow.com/g/38_2005_1_0_0_41861/Rectangle-with-rounded-corners.htm
>
> Posted via DevelopmentNow.com Groups
> http://www.developmentnow.com/g/