Click here to Skip to main content
11,495,758 members (66,507 online)
Click here to Skip to main content

CircleControl - A Circular Motion Control

, 5 Sep 2014 CPOL 82.4K 5.6K 175
Rate this:
Please Sign up or sign in to vote.
A circular motion control


This is release 1.2.2 of the library. Some minor documentation errors were corrected, the .csproj files were converted for use in Visual Studio 2013, and the help files were updated to work with the latest release of Sandcastle Help File Builder (2014.5.31.0).

The CircleControl class is a .NET 2.0 control which allows circular motion, for example, rotating a dial, or setting the hands on an analog clock.

The control supports markers - graphical objects which can be positioned programatically and/or dragged with the mouse, and marker sets, which are groups of markers which move in unison. The background may be populated with colored rings, tick marks, and text strings.


All public and protected classes, methods and properties and fully documented using standard C# XML documentation comments. The project includes a HTML help file. Refer to the Overview section in the help file for more details on using the class, and refer to the Sample Program section for a complete source listing of a working application.

The CircleControl_122_Library download includes:

CircleControl.dll Class library
CircleControl.chm Help file.

The CircleControl_122_Demo download includes the above files, as well as:

AnalogClock.exe Sample program showing an analog clock; the time may be changed by dragging the hour and minute hands.
ColorDialer.exe Sample program for picking a color; rotate the red, blue, and green dials to select the RGB values. The program is visually gratuitous demonstration of the control, and is not meant to be a serious color picker.
EditDefaults.exe Sample program demonstrating the effect of changing various CircleControl properties. It also demonstrates the new Snap feature.
GantryControl.exe Sample program as detailed in the Sample Program section of the help file.
ManyRings.exe Sample program showing excessive use of rings. Includes capability to compare paint times with FixedBackground set to true or false.

The CircleControl_122_Source download includes the source for all of above programs, as well as the necessary files for building the help file.

Compatibility with Other .NET Framework Versions

The CircleControl library is compiled using .NET Framework version 2.0. To confirm that there were no issues with other framework versions, the compiled library was used by an application which was compiled, in turn, under .NET Framework versions 3.0, 3.5, 4.0, and 4.5. The CircleControl functioned properly with all of them.

Using the code

To use the CircleControl class, simply add it on an existing form:

    CircleControl cc = new CircleControl();
    cc.Location = new System.Drawing.Point(0, 0);
    cc.Size = new System.Drawing.Size(200, 200);

By default, a new instance of CircleControl comes ready to use with a single triangular marker and ten tick marks.

To add a new marker, create a new MarkerSet, and add one or more Marker objects:

    CircleControl.MarkerSet ms = new CircleControl.MarkerSet();

    // Polygon which defines shape of marker
    PointF[] poly = new PointF[4];
    poly[0] = new PointF(0.25F,  0.00F);
    poly[1] = new PointF(0.70F,  0.18F);
    poly[2] = new PointF(0.64F,  0.00F);
    poly[3] = new PointF(0.70F, -0.18F);

    CircleControl.Marker m = new CircleControl.Marker(
                      Color.Brown,       // inside color
                      Color.DarkGreen,   // border color
                      1.0f,              // border thickness
                      poly,              // polygon defining marker shape
                      130.0f,            // angle offset of marker
                      MouseButtons.Left, // which button(s) can drag the marker
                      true);             // is marker visible?

    // Add new marker to MarkerSet, at which point
    // it becomes visible on the control

The polygon defines the appearance of the marker at angle zero. It uses a cartesian coordinate system, where (0,0) is the center of the control, and 1.0 is the distance to the nearest edge. The internal area of a marker can be a solid color, a hatch pattern, or a variety of color gradients. Borders can be of any color and thickness.

An AngleChanged event is raised whenever the angle of a marker changes, or the mouse state of a dragged marker changes. To receive events, install a handler:

    cc.AngleChanged += new CircleControl.AngleChangedHandler(OnAngleChange);

The background may be populated with colored rings, tick marks, and text strings. The following code snippet adds a beige-colored ring, and four text items, as they would be placed on a compass:

    cc.Rings.Add(new CircleControl.Ring(0.6f,        // size as radius
                                        Color.Beige, // internal color
                                        Color.Black, // border color
                                        2.0f);       // border thickness

    Font f = new Font("Arial", 8.0f);
    cc.TextItems.Add(new CircleControl.TextItem(f,         // font
                                                Color.Red, // color
                                                "N",       // text
                                                0.8f,      // distance from origin
                                                90.0f);    // angle
    cc.TextItems.Add(new CircleControl.TextItem(f, Color.Red, "S", 0.8f, 270.0f);
    cc.TextItems.Add(new CircleControl.TextItem(f, Color.Red, "E", 0.8f,   0.0f);
    cc.TextItems.Add(new CircleControl.TextItem(f, Color.Red, "W", 0.8f, 180.0f);

The internal area of a ring can be a solid color, a hatch pattern, or a variety of color gradients. Borders can be of any color and thickness. Text items can be of any font, color, or rotation. They can be a fixed size, or made to be relative to the size of the control.

The above code snippets only provide a brief overview. Refer to project help file for complete class documentation.

Points of Interest

Writing, refining, and debugging the code was, as always, a joyful experience. But documenting every public and protected class, method and property was not. It was drudgery. The pain of writing full and proper documentation was offset in part by Sandcastle Help File Builder, a freely available tool used to generate the help file. But documenting everything was a learning experience, and I've developed immense respect for programmers who write complete and useful documentation, especially for those at Microsoft who are responsible for the creation of the extensive .NET documentation.


  • September 5, 2014 - Release 1.2.2
    • Corrected minor documentation errors,
    • Converted .csproj files to Visual Studio 2013 format.
    • Converted help files to work with SandCastle Help File Builder 2014.5.31.0.
  • September 14, 2013 - Release 1.2.1
    • Fixed bug in private method CircleControl.MarkerSet.CalcSnapDist() where the snap angle may be improperly calculated if CircleControl.AngleWraps is false.
  • September 8, 2012 - Release 1.2
    • Added SnapMode and SnapAngles properties CircleControl.MarkerSet.
  • July 21, 2011 - Release 1.1.2
    • Fixed bug in CircleControl.Collections.Insert() method where the Cc parameter was improperly being set to null.
  • November 1, 2010 - Release 1.1.1
    • Fixed bug in CircleControl.SetAngleMinMax() method where the call was ignored unless both min and max parameters were different from the current values.
    • Fixed bug where marker angles were not always calculated properly if AngleWraps was false.
  • October 12, 2010 - Release 1.1
    • Added FixedBackground property to CircleControl.
  • September 12, 2010 - First release


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


About the Author

Graham Wilson
Software Developer (Senior)
Canada Canada
No Biography provided

Comments and Discussions

GeneralGreat Job!! Pin
dbrownn21-Jan-15 6:44
memberdbrownn21-Jan-15 6:44 
GeneralRe: Great Job!! Pin
Graham Wilson21-Jan-15 8:17
memberGraham Wilson21-Jan-15 8:17 
GeneralMy vote of 5 Pin
Volynsky Alex7-Sep-14 11:47
professionalVolynsky Alex7-Sep-14 11:47 
GeneralMy vote of 5 Pin
Anurag Gandhi6-Sep-14 0:09
professionalAnurag Gandhi6-Sep-14 0:09 
GeneralRe: My vote of 5 Pin
Graham Wilson6-Sep-14 2:35
memberGraham Wilson6-Sep-14 2:35 
GeneralMy vote of 5 Pin
Johann Krenn15-Sep-13 0:49
memberJohann Krenn15-Sep-13 0:49 
GeneralRe: My vote of 5 Pin
Graham Wilson15-Sep-13 16:37
memberGraham Wilson15-Sep-13 16:37 
QuestionGreat Work!! Pin
Aureocad27-Aug-13 0:20
memberAureocad27-Aug-13 0:20 
AnswerRe: Great Work!! Pin
Graham Wilson15-Sep-13 16:37
memberGraham Wilson15-Sep-13 16:37 
GeneralMy vote of 5 Pin
KD0YU30-Nov-12 4:13
memberKD0YU30-Nov-12 4:13 
QuestionCool Pin
sam.hill8-Sep-12 17:27
membersam.hill8-Sep-12 17:27 
QuestionInvert Primary Marker Pin
Todd Denlinger8-Aug-12 13:07
memberTodd Denlinger8-Aug-12 13:07 
AnswerRe: Invert Primary Marker Pin
Graham Wilson8-Aug-12 16:58
memberGraham Wilson8-Aug-12 16:58 
GeneralRe: Invert Primary Marker Pin
Todd Denlinger9-Aug-12 5:27
memberTodd Denlinger9-Aug-12 5:27 
GeneralMy vote of 5 Pin
ProEnggSoft13-Mar-12 2:06
memberProEnggSoft13-Mar-12 2:06 
GeneralMy vote of 4 Pin
mariazingzing15-Feb-12 13:56
membermariazingzing15-Feb-12 13:56 
GeneralMy vote of 5 Pin
peteSJ22-Jul-11 7:57
memberpeteSJ22-Jul-11 7:57 
Questionexcellent, and fully documented code Pin
BillWoodruff21-Jul-11 13:06
memberBillWoodruff21-Jul-11 13:06 
+5=> Thanks for this great UserControl example, with several visually interesting demo projects, and very thorough documentation, including a 'real,' help file !

fyi: no problem converting, compiling, and using, in VS 2010 Pro, .NET 4.0 Client FrameWork.

best, Bill
"Reason is the natural order of truth; but imagination is the organ of
meaning." C.S. Lewis

QuestionCool Pin
CIDev21-Jul-11 6:22
memberCIDev21-Jul-11 6:22 
QuestionGood work Pin
Shahriar Iqbal Chowdhury21-Jul-11 5:58
memberShahriar Iqbal Chowdhury21-Jul-11 5:58 
GeneralMy vote of 5 Pin
ashishkumar00831-May-11 13:19
memberashishkumar00831-May-11 13:19 
GeneralMarkers and rings Pin
jrwakeen6-Feb-11 18:19
memberjrwakeen6-Feb-11 18:19 
GeneralRe: Markers and rings Pin
Graham Wilson8-Feb-11 17:29
memberGraham Wilson8-Feb-11 17:29 
GeneralRe: Markers and rings Pin
Graham Wilson8-Feb-11 18:20
memberGraham Wilson8-Feb-11 18:20 
GeneralMy vote of 5 Pin
VistaHacker2-Nov-10 5:07
memberVistaHacker2-Nov-10 5:07 

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 | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 5 Sep 2014
Article Copyright 2010 by Graham Wilson
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid