Click here to Skip to main content
14,216,096 members
Click here to Skip to main content
Article
Posted 29 May 2006

Stats

89.7K views
6K downloads
44 bookmarked

Rounded Corners

,
Rate this:
4.14 (27 votes)
Please Sign up or sign in to vote.
4.14 (27 votes)
29 May 2006     CPOL    
Easy draw rounded corners
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)

Share

About the Author

Pavel Tsukanov
Web Developer
Russian Federation Russian Federation
No Biography provided

Comments and Discussions

 
GeneralNot easy to use Pin
Xmen Real 12-Jun-10 4:32
professional Xmen Real 12-Jun-10 4:32 
GeneralRectangle with Rounded Corners and Open top Pin
phanf24-Nov-08 13:14
memberphanf24-Nov-08 13:14 
Questionneed help using your magnificent code Pin
Shimmy Weitzhandler18-Feb-08 0:41
memberShimmy Weitzhandler18-Feb-08 0:41 
Generalone rounded corner Pin
133mmxtr17-May-07 22:31
member133mmxtr17-May-07 22:31 
GeneralRe: one rounded corner Pin
Pavel Tsukanov18-May-07 2:29
memberPavel Tsukanov18-May-07 2:29 
GeneralFantastic! Pin
Jason Troitsky15-Mar-07 9:55
memberJason Troitsky15-Mar-07 9:55 
GeneralThank you! Pin
SMan00717-Dec-06 6:44
memberSMan00717-Dec-06 6:44 
GeneralExcellent - Thank you! Pin
Mr. Accident3-Sep-06 8:24
memberMr. Accident3-Sep-06 8:24 
GeneralThanks, tell us more.. Pin
Yiyi Sun29-May-06 5:50
memberYiyi Sun29-May-06 5:50 
GeneralRe: Thanks, tell us more.. [modified] Pin
Pavel Tsukanov29-May-06 6:37
memberPavel Tsukanov29-May-06 6:37 

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

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

Layout: fixed | fluid

Article Copyright 2006 by Pavel Tsukanov
Everything else Copyright © CodeProject, 1999-2019

Server Web01
Version 2.8.190619.2