Introduction
This is release 1.2 of the library. It adds the SnapMode and SnapAngles properties to the CircleControl.MarkerSet class.
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 programmatically 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 are fully documented using standard C# XML documentation comments. The project includes an 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_12_Library download includes:
| CircleControl.dll |
Class library |
| CircleControl.chm |
Help file. |
The CircleControl_12_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. |
| 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_12_Source download includes the source for all of the above programs, as well as the necessary files for building the help file.
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);
form.Controls.Add(cc);
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();
cc.MarkerSets.Add(ms);
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, Color.DarkGreen, 1.0f, poly, 130.0f, MouseButtons.Left, true);
ms.Add(m);
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, Color.Beige, Color.Black, 2.0f);
Font f = new Font("Arial", 8.0f);
cc.TextItems.Add(new CircleControl.TextItem(f, Color.Red, "N", 0.8f, 90.0f); 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 the 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.
History
- 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