Reputation: 11
I want to draw text on the outline of a circle at fixed intervals (exactly like a clock) Is there a simple way to do that?
Upvotes: 1
Views: 1140
Reputation: 801
toddmo's math is right. In terms of the implementation, it's not clear exactly what you are asking. If you are starting from scratch, the simplest way of doing this would be:
1) create a Windows Forms app in Visual Studio
2) draw the circle in mspaint, and import the image file as a resource.
3) create a picturebox that shows that resource using the form builder UI. This is an easy way to display the circle on the form.
4) create a 'Label' control by dragging and dropping it onto the form in the form builder UI
5) create a 'Timer' control (can be drag/dropped onto the form from the 'toolbox' window)
6) double-click the Timer control, in it's event, set the Label control's position based on sin and cos as toddmo describes.
7) set the interval of the Timer control to the appropriate value.
This won't scale well if dpi changes, but it's a start.
Upvotes: 0
Reputation: 22396
Whatever graphics library you use, drawing text needs an x and a y to know where to draw the text.
Assume the center of the clock is Cx and Cy. Assume x goes positive to the right and y goes positive up. You may need to offset or reverse those depending on your platform.
So you can use math (trigonometry) to get the x and y of each clock number. You need the degree along the circle and the radius of the circle, and the formula would be:
y = sin(degree) * radius + Cy
x = cos(degree) * radius + Cx
Upvotes: 2