c#中的圆角显示 [英] circle angle display in c#
本文介绍了c#中的圆角显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个crcle有line.i想要这样做,如果我们在txt框(0-360)输入numaric值。 line移动到该角度输入文本框。
问题是如何在c#代码中移动圆圈线以显示0-360度之间的角度。
解决方案
所以此时你有代码确保你的度数值保持在0到360之间。圆圈的绘图代码在哪里?决定圆上位置的计算是一个简单的参数方程。
如何计算圆周上的圆点 [ ^ ]
圆圈方程式 [ ^ ]
http://go4answers.webhost4life.com/Example/circle-center-angle-points-circle-167588.aspx [ ^ ]
public Texture2D CreateCircle( int radius)
{
int outerRadius = radius * 2 + 2 ; // 因此圆圈不会越界
Texture2D texture = new Texture2D(GraphicsDevice,outerRadius,outerRadius);
颜色[] data = new 颜色[outerRadius * outerRadius];
// 首先将整个纹理着色透明。
< span class =code-keyword> for ( int i = 0 ; i < span class =code-keyword>< data.Length; i ++)
data [i] = Color.Transparent;
// 使用三角函数+正弦近似计算出必要的最小步骤。
double angleStep = 1f / radius;
for ( double angle = 0 ; angle < Math.PI * 2; angle + = angleStep)
{
// 使用圆的参数化定义:http://en.wikipedia.org/wiki/
int x =( int )Math.Round(radius + radius * Math.Cos(angle));
int y =( int )Math.Round(radius + radius * Math.Sin(角度));
data [y * outerRadius + x + 1 ] = Color.White;
}
texture.SetData(data);
返回纹理;
}
使用系统;
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Windows.Forms;
使用 System.Timers();
命名空间 WindowsForms
{
public partial class Form1:Form
{
int circleDiameter;
public Form1()
{
InitializeComponent();
circleDiameter = 100 ;
}
私有 void Form1_Paint(< span class =code-keyword> object sender,PaintEventArgs e)
{
Point CenterPoint = new Point()
{
X = 此 .ClientRectangle.Width / 2 ,
Y = 此 .ClientRectangle.Height / 2
};
Point topLeft = new Point()
{
X =( this .ClientRectangle.Width - circleDiameter)/ 2 ,
Y =( this .ClientRectangle.Height - circleDiameter)/ 2
};
Point topRight = new Point()
{
X =( this .ClientRectangle.Width + circleDiameter)/ 2 ,
Y =( this .ClientRectangle.Height - circleDiameter)/ 2
};
Point bottomLeft = new Point()
{
X =( this .ClientRectangle.Width - circleDiameter)/ 2 ,
Y =( this .ClientRectangle .Height + circleDiameter)/ 2
};
Point bottomRight = new Point()
{
X =( this .ClientRectangle.Width + circleDiameter)/ 2 ,
Y =( this .ClientRectangle .Height + circleDiameter)/ 2
};
e.Graphics.DrawEllipse(Pens.Red,topLeft.X,topLeft.Y,circleDiameter,circleDiameter);
e.Graphics.DrawLine(Pens.Red,CenterPoint,topLeft);
// e.Graphics.DrawLine(Pens.Black,CenterPoint,topRight);
// e.Graphics.DrawLine(Pens.Brown,CenterPoint,bottomLeft );
// e.Graphics.DrawLine(Pens.Orange, CenterPoint,bottomRight);
}
private void timer1_Tick(< span class =code-keyword> object sender,EventArgs e)
{
}
}
}
i have a crcle having line.i want to do that if we enter numaric value in txt box (0-360). line move to that angle enter in textbox.
issue is how to move circle line in c# code to show angle between 0-360 degree.
解决方案
So at this point you have code that ensures your degrees value remains between 0 and 360. Where is your drawing code for the circle? The calculation for deciding where on a circle is a simple parametric equation.
how-do-i-calculate-a-point-on-a-circles-circumference[^]
Circle Equations[^]
http://go4answers.webhost4life.com/Example/circle-center-angle-points-circle-167588.aspx[^]
public Texture2D CreateCircle(int radius) { int outerRadius = radius*2 + 2; // So circle doesn't go out of bounds Texture2D texture = new Texture2D(GraphicsDevice, outerRadius, outerRadius); Color[] data = new Color[outerRadius * outerRadius]; // Colour the entire texture transparent first. for (int i = 0; i < data.Length; i++) data[i] = Color.Transparent; // Work out the minimum step necessary using trigonometry + sine approximation. double angleStep = 1f/radius; for (double angle = 0; angle < Math.PI*2; angle += angleStep) { // Use the parametric definition of a circle: http://en.wikipedia.org/wiki/ int x = (int)Math.Round(radius + radius * Math.Cos(angle)); int y = (int)Math.Round(radius + radius * Math.Sin(angle)); data[y * outerRadius + x + 1] = Color.White; } texture.SetData(data); return texture; }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Timers(); namespace WindowsForms { public partial class Form1 : Form { int circleDiameter; public Form1() { InitializeComponent(); circleDiameter = 100; } private void Form1_Paint(object sender, PaintEventArgs e) { Point CenterPoint = new Point() { X = this.ClientRectangle.Width / 2, Y = this.ClientRectangle.Height / 2 }; Point topLeft = new Point() { X = (this.ClientRectangle.Width - circleDiameter) / 2, Y = (this.ClientRectangle.Height - circleDiameter) / 2 }; Point topRight = new Point() { X = (this.ClientRectangle.Width + circleDiameter) / 2, Y = (this.ClientRectangle.Height - circleDiameter) / 2 }; Point bottomLeft = new Point() { X = (this.ClientRectangle.Width - circleDiameter) / 2, Y = (this.ClientRectangle.Height + circleDiameter) / 2 }; Point bottomRight = new Point() { X = (this.ClientRectangle.Width + circleDiameter) / 2, Y = (this.ClientRectangle.Height + circleDiameter) / 2 }; e.Graphics.DrawEllipse(Pens.Red, topLeft.X, topLeft.Y, circleDiameter, circleDiameter); e.Graphics.DrawLine(Pens.Red, CenterPoint, topLeft); // e.Graphics.DrawLine(Pens.Black, CenterPoint, topRight); // e.Graphics.DrawLine(Pens.Brown, CenterPoint, bottomLeft); // e.Graphics.DrawLine(Pens.Orange, CenterPoint, bottomRight); } private void timer1_Tick(object sender, EventArgs e) { } } }
这篇关于c#中的圆角显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文