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);
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.
- 29th May, 2006: Initial post