用Graphic Class画string,string倒过来了,怎么会这样??
我写一个自定义控件类AlarmClock时画时间刻度,画出来刻度前后调转了。我的代码如下:protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
SetScale(g);
DrawFace(g);
}
private void SetScale(Graphics g)
{
//把坐标原点居中
g.TranslateTransform(this.Width / 2, this.Height / 2);
//将GDI+坐标转化为笛卡尔坐标系
g.ScaleTransform(1, -1);
float inches = Math.Min(Width / g.DpiX, Height / g.DpiY);
g.ScaleTransform(inches * g.DpiX / 2000, inches * g.DpiY / 2000);
}
private void DrawFace(Graphics g)
{
Brush brush = new SolidBrush(this.ForeColor);
numHrs = 12;
deg = 360 / numHrs;
FaceRadius = 700;
for (int i = 1; i <= numHrs; i++)
{
x = GetCos(90 - i * deg) * FaceRadius;
y = GetSin(90 - i * deg) * FaceRadius;
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
g.DrawString(i.ToString(), font, brush, x, y, format);
}
}
private static float GetCos(float degAngle)
{
return (float)Math.Cos(degAngle*Math.PI/180.0);
}
private static float GetSin(float degAngle)
{
return (float)Math.Sin(degAngle * Math.PI / 180.0);
}
我想是不是在SetScale那个函数里把坐标转换里出了问题呢?请高手们指教一下。 --------------------编程问答-------------------- 把显示器倒过来先凑合看着。代码等我慢慢看完。 --------------------编程问答-------------------- 问题在这句上 g.ScaleTransform(1, -1);
--------------------编程问答-------------------- 这是把它转成笛卡尔坐标,如果我要这句的话,可不可以把那些字调过来?
补充:.NET技术 , C#