Click here to Skip to main content
Click here to Skip to main content

Rounded Corners

By , 29 May 2006
Rate this:
Please Sign up or sign in to vote.
Sample Image - result.gif

Introduction

I will not be opening the big secret if I say that the library of GDI+ has gained a lot of popularity from developers of Win32 applications. Microsoft uses it in Office applications, for example Visio (I shall risk assuming, that this library has been given birth by this development). That fact became natural as .NET Framework GDI+ has come without any essential changes. As a matter of fact, classes for work with graphics are only the shell for methods of GDI+. Therefore my article will be useful for developers using GDI+ and for those who use the .NET Framework in their work.

Using the Code

While creating a small vector editor, I faced a small problem connected with rounding of corners for rectangular figures. Unfortunately, Microsoft has not provided such an ability in GDI+. Certainly it was possible to go the simple way and use a class stated in the article, Extended Graphics - An implementation of Rounded Rectangle in C#, but unfortunately this allows creating only rounded rectangles. I needed to round off corners between any direct lines as it does in Visio with such ease. Thus I had to recollect a school course of geometry and create a class, allowing rounding off corners between any set of lines consistently incorporating among themselves.

To use this class, this is simple enough. While creating a copy of the class Cpp.Diagram.Rounded.Corners, it is necessary to specify a set of points through which we pass lines, and also the radius of a rounding.

GraphicsPath path = new GraphicsPath ();
....
Cpp.Diagram.Rounded.Corners r = new Cpp.Diagram.Rounded.Corners(points, 5);
r.Execute(path);

In a variable ”path”, the graphic path which can be drawn subsequently on any graphic surface will contain it. In the figure, the result of the work of the test program shows the principle of work with my class.

History

  • 29th May, 2006: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Pavel Tsukanov
Web Developer
Russian Federation Russian Federation
No Biography provided

Comments and Discussions

 
GeneralNot easy to use PinmemberXmen W.K.12-Jun-10 4:32 
GeneralRectangle with Rounded Corners and Open top Pinmemberphanf24-Nov-08 13:14 
Questionneed help using your magnificent code PinmemberShimi Weitzhandler18-Feb-08 0:41 
Generalone rounded corner Pinmember133mmxtr17-May-07 22:31 
GeneralRe: one rounded corner PinmemberPavel Tsukanov18-May-07 2:29 
GeneralFantastic! PinmemberJason Troitsky15-Mar-07 9:55 
GeneralThank you! PinmemberSMan00717-Dec-06 6:44 
GeneralExcellent - Thank you! PinmemberMr. Accident3-Sep-06 8:24 
GeneralThanks, tell us more.. PinmemberYiyi Sun29-May-06 5:50 
GeneralRe: Thanks, tell us more.. [modified] PinmemberPavel Tsukanov29-May-06 6:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 29 May 2006
Article Copyright 2006 by Pavel Tsukanov
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid