PC Review


Reply
Thread Tools Rate Thread

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

 
 
Jose Michael Meo R. Barrido
Guest
Posts: n/a
 
      27th Nov 2004
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!


 
Reply With Quote
 
 
 
 
Mick Doherty
Guest
Posts: n/a
 
      27th Nov 2004
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" <(E-Mail Removed)> wrote in message
news:e4z%(E-Mail Removed)...
>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


 
Reply With Quote
 
Jose Michael Meo R. Barrido
Guest
Posts: n/a
 
      27th Nov 2004
thanks for your advice. i'm gonna try that :-)

"Mick Doherty"
<EXCHANGE#(E-Mail Removed).[mdaudi100#ntlworld.com]> wrote in
message news:O2%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:e4z%(E-Mail Removed)...
>>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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rounded Rectangle Vayse Microsoft Access Reports 2 31st Jul 2007 10:16 AM
Rounded Rectangle Adrian D. Bailey Microsoft Excel Programming 3 26th Mar 2007 05:58 PM
rounded rectangle ??? =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?= Microsoft Dot NET 1 24th Jan 2006 10:27 PM
Rounded Rectangle JezB Microsoft Dot NET Framework Forms 2 6th May 2005 07:18 PM
Custom Rounded Rectangle Usercontrol does not redraw controls on it. Please help. Jose Michael Meo R. Barrido Microsoft Dot NET 2 27th Nov 2004 01:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:38 AM.