ARTICLE

C# Custom Dial Control

Posted by Brad Patterson Articles | Windows Forms C# March 17, 2005
This article shows how to create and use custom dial control.
Reader Level:
Download Files:
 

My control is derived from Control and at this time does not allow the user access to the various properties in the control. Next term we will be taking this control and added Visual Studio support for properties, and will implement Gets and Sets for various parts of the control.

To use this control you must left mouse click on the control to cause the dial to increase and right mouse click to cause it to decrease. The value of the control is displayed in the center and I had problems getting the value to stay displayed while the dial is being adjusted. If anyone viewing the code and or have any ideas in how to stop this I would be greatly interested. I will also in my free time try and implement my next feature so that when the user clicks on the control the dial will move towards the point of clicking.

Here is an excerpt from the control that I made:

radius =
new Point( (int)radiusWidth, (int)radiusHeight );
//radiusEnd = new Point( (int)(radiusWidth - lineLength),
(int)radiusHeight+1 );
dotDiam = thisAreaW * 0.06f;
rotation.Scale( 1, 1 );
rotation.Rotate( count );
// The Blue Base
graphIt.DrawEllipse( penBaseDial, 5, 5, newWidth, newHeight);
// The Black Dial
graphIt.FillEllipse( brushDial, 8, 8, newWidth-5, newHeight-5 );
ShowCount();
graphIt.TranslateTransform( (
float)radiusWidth+2,(float)radiusHeight+3 );
graphIt.RotateTransform( count );
graphIt.FillEllipse( brushDotDial, -(radiusWidth-22), -10,dotDiam, dotDiam );

Here is a view of the dial and it always starts at position zero. At the extreme left position.


dialPic.gif

Login to add your contents and source code to this article
post comment
     

Hey, thanks for sharing this.  How do you get your code variables to align like that?  Are you using visual studio or an alternative IDE/ text editor?  It makes skimming the c# code even easier than skimming VB!  Plz share!  =) 

Posted by peedidblaa Jun 23, 2010
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter