最近在做一个项目,环境如下: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(); }
条件描述:窗体有个背景图片,图片上有个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(); }
解决方案 »
- 用VC2008作了一个安装部署项目,但是在添加桌面快捷方式图标与程序快捷方式图标的时候出错。
- c#循环中对象实例的疑问
- spring.net能用来干啥?
- 没有语言基础适合学习C#吗?
- Visual C# 关于Access数据库,程序在编译时会把旧的Access数据库复制到 Bin 目录中,将原来的数据库覆盖的问题???
- 怎么声明主体?
- C#视频聊天程序难题
- ?关于网页中的“浏览”按钮
- 关于c#进行update操作excel 2007及以后版本的xlsx格式表格报"操作必须使用一个可更新的查询。"错误
- 大家来找碴——又是语法错误,在线!!
- 在C#中生成.gz压缩文件,但为什么和正常的.gz压缩文件不同,win7选中文件预览窗口显示为"没有预览",双击打开时显示要输入压缩文件名,点确认后才能打开压缩
- vs2015怎么设置背景图后,在上面加控件?
是每秒钟刷新一次picturebox
一般双缓冲可以极大改善这个现象
但是不知道你设置双缓冲的代码是怎么写的
2.Double Buffer是需要的,先在内存中定义一张位图,把内容画在这张位图上,再在Paint事件中把这张位图画出来,网上资料很多,自行查找。