468,257 Members | 1,413 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,257 developers. It's quick & easy.

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

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!
Jul 21 '05 #1
2 1924
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.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Jose Michael Meo R. Barrido" <mi**@rdmsinc.net> wrote in message
news:e4****************@TK2MSFTNGP11.phx.gbl...
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!

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.802 / Virus Database: 545 - Release Date: 26/11/2004
Jul 21 '05 #2
thanks for your advice. i'm gonna try that :-)

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:O2****************@TK2MSFTNGP10.phx.gbl...
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.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Jose Michael Meo R. Barrido" <mi**@rdmsinc.net> wrote in message
news:e4****************@TK2MSFTNGP11.phx.gbl...
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!

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.802 / Virus Database: 545 - Release Date: 26/11/2004

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Daisy | last post: by
2 posts views Thread by Dino Buljubasic | last post: by
6 posts views Thread by moondaddy | last post: by
4 posts views Thread by =?Utf-8?B?UmljaEI=?= | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.