使用C#来绘制汽车里程表

 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();
  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值