Re: Making frame with GDI+

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Anushi (anushiagarwal_at_rediffmail.com)
Date: 03/09/04


Date: Tue, 9 Mar 2004 15:14:48 +0530

Hi James

Try this :
Start code
******************************************
Private Function GetRoundedRect(ByVal BaseRect As RectangleF, ByVal
Radius As Single) As Region
' If corner radius is less than or equal to zero, return the
original rectangle
If Radius <= 0 Then Return New Region(BaseRect)
' If corner radius is greater than or equal to half the width or
height (whichever is shorter) then
' return a capsule instead of a lozenge.
If Radius >= (Math.Min(BaseRect.Width, BaseRect.Height) / 2.0) Then
Return GetCapsule(BaseRect)

Dim Diameter As Single = Radius + Radius
Dim ArcRect As New RectangleF(BaseRect.Location, New SizeF(Diameter,
Diameter))
Dim RR As New Drawing2D.GraphicsPath()
With RR
' top left arc
.AddArc(ArcRect, 180, 90)

' top right arc
ArcRect.X = BaseRect.Right - Diameter
.AddArc(ArcRect, 270, 90)

' bottom right arc
ArcRect.Y = BaseRect.Bottom - Diameter
.AddArc(ArcRect, 0, 90)

' bottom left arc
ArcRect.X = BaseRect.Left
.AddArc(ArcRect, 90, 90)

.CloseFigure()
End With

Return New Region(RR)
End Function

------------------------------------

Private Function GetCapsule(ByVal BaseRect As RectangleF) As Region
Dim Diameter As Single
Dim ArcRect As RectangleF
Dim RR As New Drawing2D.GraphicsPath()

With RR
Try
If BaseRect.Width > BaseRect.Height Then
' Return horizontal capsule
Diameter = BaseRect.Height
ArcRect = New RectangleF(BaseRect.Location, New
SizeF(Diameter, Diameter))
.AddArc(ArcRect, 90, 180)
ArcRect.X = BaseRect.Right - Diameter
.AddArc(ArcRect, 270, 180)

ElseIf BaseRect.Height > BaseRect.Width Then
' Return vertical capsule
Diameter = BaseRect.Width
ArcRect = New RectangleF(BaseRect.Location, New
SizeF(Diameter, Diameter))
.AddArc(ArcRect, 180, 180)
ArcRect.Y = BaseRect.Bottom - Diameter
.AddArc(ArcRect, 0, 180)

Else
' return circle
.AddEllipse(BaseRect)
End If

Catch e As Exception
.AddEllipse(BaseRect)
Finally
.CloseFigure()
End Try
End With

Return New Region(RR)
End Function
********************************************************
End code

Hope this helps.
Regards,
Anushi

"James Steward" <anonymous@discussions.microsoft.com> wrote in message
news:E22542E8-4118-4196-8C43-B308BA8E40A0@microsoft.com...
> Hi,
>
> In one of my programs, I want to paint a frame around some controls via
GDI+. The frame should have rounded corners.
> But as I'm really a newbie to programming, I just don't know how to do
this via GDI+ and .net. Could anyone help me?
>
>
> Thanks
> James
>
>



Relevant Pages

  • Re: need help with homework
    ... So if you solve for circumference you get pi x diameter, ... Now if you know relation between diameter and radius, ... Center of circle splits diameter into two radii. ... circular disk, i.e. a disk whose perimiter is a circle. ...
    (sci.math)
  • Re: Spring Valve for Inverted 5 Gal Plastic Can
    ... Depends on the diameter - angular acceleration is given by omega squared ... So if your bowl was 150mm dia the acceleration ... That implies a radius of about 95mm ...
    (uk.rec.models.engineering)
  • Re: Mori Seki SL1 NC lathe programming
    ... On the face of a 1.0" diameter using a .031 TNR. ... Bar is ... Let's see you post the same programming from the center of the radius. ...
    (alt.machines.cnc)
  • Re: Mori Seki SL1 NC lathe programming
    ... Cliff wrote: ... programming SFM. ... you set your zero point from on the radius, the tip of that insert will ... Why is programming a 1" diameter ...
    (alt.machines.cnc)
  • Re: Move an object on a form in an arc!
    ... Alastair MacFarlane ... bogged down in the maths of radius, ... Private CX As Single, CY As Single ... Private Function GetXAs Single ...
    (microsoft.public.vb.general.discussion)