Avatar of Ryan
Ryan
Flag for United States of America

asked on 

Form Custom Background on Paint

I'm trying to make a form with rounded corners and eventually a gradient background.

The following code seems to occur on the paint of every control causing the attached image.
Private Sub frmFilter_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Debug.Write(sender.GetType.ToString & vbCrLf)
 
        Dim r As System.Drawing.Drawing2D.GraphicsPath = RoundRect(e.ClipRectangle, 9)
        e.Graphics.FillPath(Brushes.SteelBlue, r)
        e.Graphics.DrawPath(Pens.Black, r)
    End Sub
 
 
    Public Function RoundRect(ByVal rect As Rectangle, ByVal Radius As Integer) As System.Drawing.Drawing2D.GraphicsPath
        ' Creates a round rect shape'
        ' <param name="rectangle">Rectangle of the shape</param>'
        ' <param name="roundRadius">Radius of the round corners, in pixels</param>'
        ' <returns>The round-rect path</returns>'
 
        Dim innerRect As Rectangle = Rectangle.Inflate(rect, -Radius, -Radius)
        RoundRect = New System.Drawing.Drawing2D.GraphicsPath()
        With RoundRect
            .StartFigure()
            .AddArc(RoundBounds(innerRect.Right - 1, innerRect.Bottom - 1, Radius), 0, 90)
            .AddArc(RoundBounds(innerRect.Left, innerRect.Bottom - 1, Radius), 90, 90)
            .AddArc(RoundBounds(innerRect.Left, innerRect.Top, Radius), 180, 90)
            .AddArc(RoundBounds(innerRect.Right - 1, innerRect.Top, Radius), 270, 90)
            .CloseFigure()
        End With
 
    End Function

Open in new window

Menu.gif
.NET ProgrammingEditors IDEsVisual Basic.NET

Avatar of undefined
Last Comment
rachitkohli

8/22/2022 - Mon