Private void DrawLine( float fThickness, float fLength, Color color,įloat fRadians, e)Į.Graphics.DrawLine( new Pen( color, fThickness ),įCenterX - ( float)(fLength/9*(fRadians)),įCenterY + ( float)(fLength/9*(fRadians)),įCenterX + ( float)(fLength*(fRadians)),įCenterY - ( float)(fLength*(fRadians))) We first need to find the values of current time. Hence, we have to write some code to convert this polar quantity to a rectangular one because C# graphics doesn’t understand polar coordinate system we have to specify the x and y coordinates of the hand. The minute/hour/second values are nothing but a function of the angular displacement of the hand. The positions of hands in a clock are specified in polar coordinate system. To start with our clock, we need some mathematics. It also assumes that you have some basic knowledge of high school mathematics. This article is for you if you are new to C# controls but quite familiar with C# and its syntax.
Being a component, we can add our control to the toolbox, drop it on a form, and draw it to any dimension, it will look fine. There are certain settings to make the control customizable.
This article shows how to create an analog clock control in C# using simple and efficient coding, and such that it adjusts itself whenever resized to new dimensions.