使用C#来绘制汽车里程表
2004-11-10 16:59
591 查看
private void Form3_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g=this.CreateGraphics();
Rectangle rect=this.ClientRectangle;
//设置高度和宽
int WIDTH=rect.Width/2;
int HEIGHT=rect.Height/2;
g.SmoothingMode=SmoothingMode.AntiAlias;
FontFamily f=new FontFamily("宋体");
Font font=new Font(f,14,FontStyle.Bold,GraphicsUnit.Pixel);
g.TranslateTransform(WIDTH/2,HEIGHT/2);//原点设在窗口中心
g.FillEllipse(new SolidBrush(Color.Black),HEIGHT/-2,HEIGHT/-2,HEIGHT,HEIGHT);
g.DrawString("公里/小时",font,new SolidBrush(Color.Green),new PointF(-26,HEIGHT/-4-font.GetHeight(0.0f)+20));
g.RotateTransform(225);
for(int x=0;x<55;x++)
{
g.FillRectangle(new SolidBrush(Color.Green),-2,(HEIGHT/2-2)*-1,3,15);
g.RotateTransform(5);
}
g.ResetTransform();
g.TranslateTransform(WIDTH/2,HEIGHT/2);
g.RotateTransform(225);
int sp=0;
string tmp;
for(int x=0;x<7;x++)
{
tmp=sp.ToString();
g.FillRectangle(new SolidBrush(Color.Red),-3,(HEIGHT/2-2)*-1,6,25);
g.DrawString(tmp,
font,
new SolidBrush(Color.Green),new PointF(tmp.Length*-6,(HEIGHT/-2)+25));
g.RotateTransform(45);
sp+=20;
//g.DrawString(
}
g.ResetTransform();
g.TranslateTransform(WIDTH/2,HEIGHT/2);
float angle;
angle=(float)(30.0*2.25)+225;
g.RotateTransform(angle);
Pen p=new Pen(Color.Blue,14);
p.EndCap=LineCap.ArrowAnchor;
p.StartCap=LineCap.RoundAnchor;
g.DrawLine(p,new PointF(0,0),new PointF(0,-1*(HEIGHT/2.75f)));
g.ResetTransform();
g.TranslateTransform(WIDTH/2,HEIGHT/2);
g.FillEllipse(new SolidBrush(Color.Black),-6,-9,14,14);
g.FillEllipse(new SolidBrush(Color.Red),-7,-7,14,14);
p.Width=4.0f;
p.Color=Color.Black;
p.EndCap=LineCap.Round;
p.StartCap=LineCap.Flat;
g.DrawLine(p,new PointF(HEIGHT/15.75f,HEIGHT/3.95f),new PointF(HEIGHT/10.75f,HEIGHT/5.2f));
p.Color=Color.Red;
g.DrawLine(p,new PointF(HEIGHT/15.75f,HEIGHT/3.95f),new PointF(HEIGHT/15.75f,HEIGHT/4.6f));
g.Dispose();
}
{
Graphics g=this.CreateGraphics();
Rectangle rect=this.ClientRectangle;
//设置高度和宽
int WIDTH=rect.Width/2;
int HEIGHT=rect.Height/2;
g.SmoothingMode=SmoothingMode.AntiAlias;
FontFamily f=new FontFamily("宋体");
Font font=new Font(f,14,FontStyle.Bold,GraphicsUnit.Pixel);
g.TranslateTransform(WIDTH/2,HEIGHT/2);//原点设在窗口中心
g.FillEllipse(new SolidBrush(Color.Black),HEIGHT/-2,HEIGHT/-2,HEIGHT,HEIGHT);
g.DrawString("公里/小时",font,new SolidBrush(Color.Green),new PointF(-26,HEIGHT/-4-font.GetHeight(0.0f)+20));
g.RotateTransform(225);
for(int x=0;x<55;x++)
{
g.FillRectangle(new SolidBrush(Color.Green),-2,(HEIGHT/2-2)*-1,3,15);
g.RotateTransform(5);
}
g.ResetTransform();
g.TranslateTransform(WIDTH/2,HEIGHT/2);
g.RotateTransform(225);
int sp=0;
string tmp;
for(int x=0;x<7;x++)
{
tmp=sp.ToString();
g.FillRectangle(new SolidBrush(Color.Red),-3,(HEIGHT/2-2)*-1,6,25);
g.DrawString(tmp,
font,
new SolidBrush(Color.Green),new PointF(tmp.Length*-6,(HEIGHT/-2)+25));
g.RotateTransform(45);
sp+=20;
//g.DrawString(
}
g.ResetTransform();
g.TranslateTransform(WIDTH/2,HEIGHT/2);
float angle;
angle=(float)(30.0*2.25)+225;
g.RotateTransform(angle);
Pen p=new Pen(Color.Blue,14);
p.EndCap=LineCap.ArrowAnchor;
p.StartCap=LineCap.RoundAnchor;
g.DrawLine(p,new PointF(0,0),new PointF(0,-1*(HEIGHT/2.75f)));
g.ResetTransform();
g.TranslateTransform(WIDTH/2,HEIGHT/2);
g.FillEllipse(new SolidBrush(Color.Black),-6,-9,14,14);
g.FillEllipse(new SolidBrush(Color.Red),-7,-7,14,14);
p.Width=4.0f;
p.Color=Color.Black;
p.EndCap=LineCap.Round;
p.StartCap=LineCap.Flat;
g.DrawLine(p,new PointF(HEIGHT/15.75f,HEIGHT/3.95f),new PointF(HEIGHT/10.75f,HEIGHT/5.2f));
p.Color=Color.Red;
g.DrawLine(p,new PointF(HEIGHT/15.75f,HEIGHT/3.95f),new PointF(HEIGHT/15.75f,HEIGHT/4.6f));
g.Dispose();
}
相关文章推荐
- C#2.0新特性 - 友元程序集(Friend Assemblies)
- C#中的cookie编程
- 如何在c#2005express的MenuStrip中实现item分隔(Done)
- 解读C#中的正则表达式
- 发表一个自己C#写的email 初级系统源代码
- 关于Visual C#装箱与拆箱的研究
- Visual C# .NET 2003 语言的改变
- C# 编程语言的未来功能
- CSharp Stringbuiler
- C#实现的18位身份证格式验证算法[转载]
- ]如何点击按钮弹出新窗口,输入数据后返回并刷新页面?(C#代码)
- C++编程人员容易犯的10个C#错误
- C#捕捉视频头(源码)
- 一个手机短信息的编解码类(c#)
- C# 1.x 实现 "强类型元素唯一的 ArrayList"
- C# 1.x 实现 "强类型元素唯一的 ArrayList"
- C#写的UBB代码
- C#实现listview中节点的拖拉
- c# encrypt
- 利用C#显示MP3的标签信息