SIGN UP MEMBER LOGIN:    
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
share 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
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor