Re: Making frame with GDI+
From: Anushi (anushiagarwal_at_rediffmail.com)
Date: 03/09/04
- Next message: Andrej Tozon: "Re: Forms and shortcuts"
- Previous message: fix: "logging application block"
- In reply to: James Steward: "Making frame with GDI+"
- Next in thread: James Steward: "Re: Making frame with GDI+"
- Reply: James Steward: "Re: Making frame with GDI+"
- Messages sorted by: [ date ] [ thread ]
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
>
>
- Next message: Andrej Tozon: "Re: Forms and shortcuts"
- Previous message: fix: "logging application block"
- In reply to: James Steward: "Making frame with GDI+"
- Next in thread: James Steward: "Re: Making frame with GDI+"
- Reply: James Steward: "Re: Making frame with GDI+"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|