Hi All,

I have a porblem with drawing a rounded rectangle.
The function gives me an error:

Function 'GetRoundedRectPath' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.
Here's my code;

Code:
Public Class Form1
    Dim g As Graphics
    Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
        Application.Exit()
    End Sub

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

    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        Dim width As Integer = Me.ClientRectangle.Width
        Dim heigth As Integer = Me.ClientRectangle.Height
        Dim rect As Rectangle = New Rectangle(10, 20, width - 20, heigth - 20)
        Dim path As GraphicsPath = getRoundedRectPath(rect, CInt(width / 10))
        g.FillPath(Brushes.LavenderBlush, path)
        g.DrawPath(Pens.Peru, path)


    End Sub
    Function GetRoundedRectPath(rect As Rectangle, ByVal radius As Integer) As GraphicsPath
        Dim diameter As Integer = 2 * radius
        Dim arcrect As Rectangle = New Rectangle(rect.Location, New Size(diameter, diameter))
        Dim path As GraphicsPath = New GraphicsPath()

        ' top left
        path.AddArc(arcrect, 180, 90)

        ' top right
        path.AddArc(arcrect, 270, 90)

        ' bottem right
        path.AddArc(arcrect, 0, 90)

        ' bottem left
        path.AddArc(arcrect, 90, 90)

        path.CloseFigure()

    End Function
End Class
Thanks in advance,

sparrow1