最近在做一个项目,环境如下:WINCE6.0,C#,WINFORM;
条件描述:窗体有个背景图片,图片上有个Label标签,用于动态显示实时日期时间;
问题描述:用Timer每隔1秒显示Label当前时间的时候,标签总是会闪动,网上找了一堆的资料都说是双缓存,但是都没有解决这个问题,求完整示例代码;另外:现在用WINCE开发项目的人还多吗?什么项目中用到比较多?代码如下:
 private void InitForm()
        {
            lbDateTime.ForeColor = Color.White;
            this.lbDateTime.Text = DateTime.Now.ToString();
        } private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            
         
            Bitmap bufferBMP = new Bitmap("\\Program Files\\DEMO\\default2.jpg");
            Graphics g_bmp =  Graphics.FromImage(bufferBMP);
        
            foreach (Control C in this.Controls)
            {
                if (C is Label)
                {
                    Label L = (Label)C;
                    L.Visible = false;                    g_bmp.DrawString(L.Text, L.Font, new SolidBrush(L.ForeColor), L.Left - pictureBox1.Left, L.Top - pictureBox1.Top);
                }
            }
     
            
           // this.Refresh();
         
            Graphics g = e.Graphics;
            if (g == null) return;
            if (g_bmp != null)
            {
               g.DrawImage(bufferBMP, 0, 0);
               
            }
            bufferBMP.Dispose();
            g_bmp.Dispose();
            g.Dispose();
                     }
 private void timer1_Tick(object sender, EventArgs e)
        {
            lbDateTime.Text = DateTime.Now.ToString();            this.pictureBox1.Refresh();         }

解决方案 »

  1.   

    你这个不是label的问题
    是每秒钟刷新一次picturebox
    一般双缓冲可以极大改善这个现象
    但是不知道你设置双缓冲的代码是怎么写的
      

  2.   

    1.PictureBox是用来加载和显示位图的,不是让你在上面做绘制,你可以在Panel或者UserControl上绘制位图,但真心不该用PictureBox。
    2.Double Buffer是需要的,先在内存中定义一张位图,把内容画在这张位图上,再在Paint事件中把这张位图画出来,网上资料很多,自行查找。