Custom Rounded Rectangle Usercontrol does not redraw controls on it. Please help.

  • Thread starter Jose Michael Meo R. Barrido
  • Start date
J

Jose Michael Meo R. Barrido

I made a custom runded rectangle usercontrol. I used a function i found on
the internet. the function works fine(see "GetRoundRect" below).
I use the fullowing code to make my usercontrol rounded....
*****************************************************
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim x1 As Integer = 0
Dim x2 As Integer = Me.ClientSize.Width
Dim iHeight As Int32 = Me.Height
Dim iWidth As Int32 = Me.Width
If bCurveSided Then
Dim eg As New ExtendedGraphics(e.Graphics)
Dim rf As New RectangleF()
With rf
.Width = iWidth
.Height = iHeight
.X = 1
.Y = 0
End With
Me.Region = New Region(eg.GetRoundedRect(rf, 5))
End If
End Sub

Public Function GetRoundedRect(ByVal baseRect As RectangleF, ByVal
radius As Single) As GraphicsPath
If radius <= 0 Then
Dim mPath As GraphicsPath = New GraphicsPath()
mPath.AddRectangle(baseRect)
mPath.CloseFigure()
Return mPath
End If
If radius >= (Math.Min(baseRect.Width, baseRect.Height)) / 2 Then
Return GetCapsule(baseRect)
End If
Dim diameter As Single = radius * 2
Dim sizeF As SizeF = New SizeF(diameter, diameter)
Dim arc As RectangleF = New RectangleF(baseRect.Location, sizeF)
Dim path As GraphicsPath = New GraphicsPath()
path.AddArc(arc, 180, 90)
arc.X = baseRect.Right - diameter
path.AddArc(arc, 270, 90)
arc.Y = baseRect.Bottom - diameter
path.AddArc(arc, 0, 90)
arc.X = baseRect.Left
path.AddArc(arc, 90, 90)
path.CloseFigure()
Return path
End Function
**************************************

My question is...why is it when i use my custom rounded usercontrol and put
some textboxes on it. The controls on my usercontrol does not redraw
properly? i have to manualy tell my usercontrol to repaint itself. like....
Me.Refresh. Plrease help!
 
M

Mick Doherty

What are ExtendedGraphics() and GetCapsule()?

Why not:
Me.Region = New Region(GetRoundedRect(rf, 5))

and what happens if you add the following to your OnPaint method?
MyBase.OnPaint(e)

I would recommend setting the region in the usercontrols OnResize method
rather than in the OnPaint method.
 
Top