Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Rounded Corners

0.00/5 (No votes)
29 May 2006 1  
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here