Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2004

Tip: Looking for answers? Try searching our database.

Rectangle curved edges

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Wood - 08 Jul 2004 18:06 GMT
Do anyone know an easy way to draw rectangles with curved edges? I couldn't
see anything in Graphics that would provide that.

Thanks in advance.

Signature

    John Wood
    EMail: first name, dot, second name at priorganize.com

Tim Wilson - 08 Jul 2004 18:20 GMT
You mean a rounded rectangle? You'll have to draw this yourself. You can do
this with a GraphicsPath object.
http://www.google.ca/groups?hl=en&lr=&ie=UTF-8&selm=%235a7uAiNCHA.2456%40tkmsftngp08

Signature

Tim Wilson
.Net Compact Framework MVP

> Do anyone know an easy way to draw rectangles with curved edges? I couldn't
> see anything in Graphics that would provide that.
>
> Thanks in advance.
John Wood - 08 Jul 2004 18:31 GMT
Ah thank you.

Signature

    John Wood
    EMail: first name, dot, second name at priorganize.com

> You mean a rounded rectangle? You'll have to draw this yourself. You can do
> this with a GraphicsPath object.

http://www.google.ca/groups?hl=en&lr=&ie=UTF-8&selm=%235a7uAiNCHA.2456%40tkmsftngp08

> > Do anyone know an easy way to draw rectangles with curved edges? I
> couldn't
> > see anything in Graphics that would provide that.
> >
> > Thanks in advance.
John Wood - 08 Jul 2004 19:01 GMT
For anyone who's interested, I converted that code to C#:

 public GraphicsPath GetGraphicsPath(int x, int y, int width, int height,
int radius)
 {
  GraphicsPath gp = new GraphicsPath();
  gp.AddLine(x + radius, y, x + width - radius, y);
  gp.AddArc(x + width - radius, y, radius, radius, 270, 90);
  gp.AddLine(x + width, y + radius, x + width, y + height - radius);
  gp.AddArc(x + width - radius, y + height - radius, radius, radius, 0,
90);
  gp.AddLine(x + width - radius, y + height, x + radius, y + height);
  gp.AddArc(x, y + height - radius, radius, radius, 90, 90);
  gp.AddLine(x, y + height - radius, x, y + radius);
  gp.AddArc(x, y, radius, radius, 180, 90);
  gp.CloseFigure();
  return gp;
 }

 public void DrawRoundRect(Graphics g, Pen p, int x, int y, int width, int
height, int radius)
 {
  GraphicsPath gp = GetGraphicsPath(x, y, width, height, radius);
  g.DrawPath(p, gp);
  gp.Dispose();
 }

 public void FillRoundRect(Graphics g, Brush b, int x, int y, int width,
int height, int radius)
 {
  GraphicsPath gp = GetGraphicsPath(x, y, width, height, radius);
  g.FillPath(b, gp);
  gp.Dispose();
 }

Signature

    John Wood
    EMail: first name, dot, second name at priorganize.com

> You mean a rounded rectangle? You'll have to draw this yourself. You can do
> this with a GraphicsPath object.

http://www.google.ca/groups?hl=en&lr=&ie=UTF-8&selm=%235a7uAiNCHA.2456%40tkmsftngp08

> > Do anyone know an easy way to draw rectangles with curved edges? I
> couldn't
> > see anything in Graphics that would provide that.
> >
> > Thanks in advance.
Bob Powell [MVP] - 08 Jul 2004 18:34 GMT
The GDI+ FAQ has answers to this and many other questions

Signature

Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml

> Do anyone know an easy way to draw rectangles with curved edges? I couldn't
> see anything in Graphics that would provide that.
>
> Thanks in advance.
John Wood - 08 Jul 2004 19:03 GMT
So it does.. thanks Bob.

Signature

    John Wood
    EMail: first name, dot, second name at priorganize.com

> The GDI+ FAQ has answers to this and many other questions
>
[quoted text clipped - 3 lines]
> >
> > Thanks in advance.
John Wood - 08 Jul 2004 19:44 GMT
Just thought I'd let you know that I *LOVE* the new halo effect sample. Will
look very nice in my splash screen!

Thanks.

Signature

    John Wood
    EMail: first name, dot, second name at priorganize.com

> The GDI+ FAQ has answers to this and many other questions
>
[quoted text clipped - 3 lines]
> >
> > Thanks in advance.
Herfried K. Wagner [MVP] - 08 Jul 2004 20:54 GMT
* "John Wood" <spam@isannoying.com> scripsit:
> Do anyone know an easy way to draw rectangles with curved edges? I couldn't
> see anything in Graphics that would provide that.

P/invoke on 'RoundRect':

\\\
Private Declare Function RoundRect Lib "gdi32.dll" ( _
   ByVal hdc As IntPtr, _
   ByVal X1 As Int32, _
   ByVal Y1 As Int32, _
   ByVal X2 As Int32, _
   ByVal Y2 As Int32, _
   ByVal X3 As Int32, _
   ByVal Y3 As Int32 _
) As Int32
///

Signature

Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/

Bob Powell [MVP] - 08 Jul 2004 21:11 GMT
That was too simple :-))

Signature

Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml

> * "John Wood" <spam@isannoying.com> scripsit:
> > Do anyone know an easy way to draw rectangles with curved edges? I couldn't
[quoted text clipped - 13 lines]
> ) As Int32
> ///
Herfried K. Wagner [MVP] - 08 Jul 2004 21:42 GMT
* "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> scripsit:
> That was too simple :-))

I didn't test it, but doesn't it work?

Signature

Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/

John Wood - 08 Jul 2004 22:32 GMT
I assume that would ignore the smoothing mode and stuff though...
Wouldn't it?

Signature

    John Wood
    EMail: first name, dot, second name at priorganize.com

> * "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> scripsit:
> > That was too simple :-))
>
> I didn't test it, but doesn't it work?
Tim Wilson - 08 Jul 2004 22:52 GMT
I would think so. And I would also assume that, since a Graphics object is
stateless, other things such as line style, color, thickness, etc would also
not be easily accessible without having to SelectObject/DeleteObject
everything into the underlying device context.

IntPtr hDC = e.Graphics.GetHdc();
// Create objects, select them in, select them out, and then delete them.
e.Graphics.ReleaseHdc(hDC);

But for a simple rounded rect the P/Invoke to RoundRect is good.

Signature

Tim Wilson
.Net Compact Framework MVP

> I assume that would ignore the smoothing mode and stuff though...
> Wouldn't it?
[quoted text clipped - 3 lines]
> >
> > I didn't test it, but doesn't it work?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.