简体   繁体   English

如何在C#中绘制圆的轮廓?

[英]How can I draw on the outline of a circle in C#?

我想以固定的时间间隔(就像时钟一样)在圆的轮廓上绘制文本吗?有没有一种简单的方法?

Whatever graphics library you use, drawing text needs an x and ay to know where to draw the text. 无论使用哪种图形库,绘制文本都需要使用x和ay才能知道在何处绘制文本。

Assume the center of the clock is Cx and Cy. 假设时钟的中心是Cx和Cy。 Assume x goes positive to the right and y goes positive up. 假设x向右偏正,而y向上偏正。 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. 因此,您可以使用数学(三角函数)来获取每个时钟数字的x和y。 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

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 1)在Visual Studio中创建Windows窗体应用

2) draw the circle in mspaint, and import the image file as a resource. 2)在mspaint中绘制圆,然后将图像文件作为资源导入。

3) create a picturebox that shows that resource using the form builder UI. 3)使用窗体构建器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 4)通过将其拖放到表单构建器UI中的表单上来创建“标签”控件

5) create a 'Timer' control (can be drag/dropped onto the form from the 'toolbox' window) 5)创建一个“计时器”控件(可以从“工具箱”窗口拖放到窗体上)

6) double-click the Timer control, in it's event, set the Label control's position based on sin and cos as toddmo describes. 6)双击Timer控件,在这种情况下,根据toddmo描述的sin和cos设置Label控件的位置。

7) set the interval of the Timer control to the appropriate value. 7)将Timer控件的间隔设置为适当的值。

This won't scale well if dpi changes, but it's a start. 如果dpi改变,这将无法很好地扩展,但这是一个开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM