I’ve created a simple solution with 2 projects. The 1st project (class library) contains a custom control called Container which draws itself with rounded corners. The 2nd project (windows forms) is a test application.
If I add a Container instance to main Form in the 2nd project it shows the rounded corners nicely. Also when I run the 2nd project I can see the Container.
However when I start moving the form (click and hold the title bar), especially when I move it very fast, all the drawing is messed up, drawn over and over again but not clearing it’s surface first…
I can call Container1.Refresh() in the Form1.Move event, but I don’t want to set this every time because this also means I have to call Container1.Refresh() in the Form1.Resize event and who knows which other event…
Is there an event in the Container (control) class itself where I should call Me.Refresh() or Me.Update() or Me.Invalidate() ?
For reference (Form1.vb)
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move Me.Container1.Refresh() End Sub End Class
for reference (Container.vb):
Imports System.Windows.Forms Imports System.Drawing Imports System.Drawing.Drawing2D Public Class Container : Inherits Control Private _Gp As GraphicsPath Private Sub Container_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim r As Rectangle = e.ClipRectangle Dim gp As New GraphicsPath Dim cs As Integer = 25 'CornerSize' r.Inflate(-5, -5) gp.AddArc(r.X, r.Y, cs, cs, 180, 90) gp.AddArc(r.X + r.Width - cs, r.Y, cs, cs, 270, 90) gp.AddArc(r.X + r.Width - cs, r.Y + r.Height - cs, cs, cs, 0, 90) gp.AddArc(r.X, r.Y + r.Height - cs, cs, cs, 90, 90) Dim t As Single = cs / 2 + r.Y gp.AddLine(r.X, r.Y + r.Height - cs, r.X, t) e.Graphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias e.Graphics.DrawPath(Pens.Black, gp) End Sub End Class
This is your problem:
Change it to: