Windows窗体应用程序C#中的计时器 [英] Timer in Windows Form Application C#

查看:111
本文介绍了Windows窗体应用程序C#中的计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计时器以Windows格式擦除背景?我清除屏幕并再次添加背景,但计时器消失。如何在没有弄乱我的背景图像的情况下使用计时器?

Timer erases background in windows form? I clear the screen and add the background again, but then the timer disappears. How can I use the timer without it messing with my background image?

推荐答案

或许类似下面的内容?



Something like the following perhaps?

public partial class Form1 : Form
{

  private Timer t;

  public Form1()
  {
    InitializeComponent();
    t = new Timer();
    t.Tick += new EventHandler(t_Tick);
    t.Interval = 3000;
    t.Enabled = true;

    this.BackgroundImage = new Bitmap(@"C:\@Download\Images\Aero\FaireyFirefly.bmp");

  }

  void t_Tick(object sender, EventArgs e)
  {

    // Pick font, size and colour for the timer legend.
    Font drawFont = new Font("Arial", 16);
    SolidBrush drawBrush = new SolidBrush(Color.Black);
    PointF drawPoint = new PointF(10.0F, 10.0F);
    Graphics g = this.CreateGraphics();

    String legend = DateTime.Now.ToLongTimeString();

    // Hard coded for simpliciity.
    // Use g.MeasureString to get the correct size of the required output area.
    // Clear the previous op.
    Rectangle r = new Rectangle(10,10,100,30);
    Invalidate(r);
    Update();

    // Paint the string we want.
    g.DrawString(legend, drawFont, drawBrush, drawPoint);
    g.Dispose();

  }
}


非常感谢兄弟分享您使用过的知识和信息代码和工作正常,非常感谢
Thank you so much brother for sharing your knowledge and information i used your code and working properly thanks alot


这篇关于Windows窗体应用程序C#中的计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆