做一个在屏幕飞过的文本效果,为什么闪得厉害,求高手指点好方法
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Random ran = new Random();
int sjs = ran.Next(1, 260);
for (int i = 1; i < 30; i++)
{
//panel1.Controls.Clear();
Label hj = new Label();
hj.Name = "hj " + i;
hj.Text = "2wqwer ";
hj.Font = button1.Font;
hj.Location = new System.Drawing.Point(10 * i, sjs);
panel1.Controls.Add(hj);
Application.DoEvents();
Thread.Sleep(40);
}
Button hj1 = new Button();
hj1.Text = "再来 ";
hj1.Font = button1.Font;
hj1.Location = new System.Drawing.Point(107,88);
hj1.Click += new EventHandler(button1_Click);
hj1.Size = button1.Size;
panel1.Controls.Add(hj1);
}
}
}
[解决办法]
你的代码好像有问题啊...
你最好用画图来实现这个功能,在Form上建立一个Graphics对象,然后用DrawString来在指定的位置输出文字就行了,如果要效果好点的,你可以用双绶冲绘图.
[解决办法]
不要用Thread.Sleep,最好用Timer代替~~~
[解决办法]
同一楼,用GDI+,还有this.DoubleBuffered = true;
[解决办法]
使用 Label 绝对闪呀!!最好用!!DrawString画文本!!
[解决办法]
顶
[解决办法]
最好还是使用GDI+函数
性能好一些吧
[解决办法]
你不用每次都生成一个新的标签:Label hj = new Label();
你也不用每次调用
panel1.Controls.Add(hj);
及
panel1.Controls.Remove(hj);
这两个语句操作一次就行了,只需每次调用
hj.Location = new System.Drawing.Point(10 * i, sjs);
就行.
[解决办法]
最好用画图来实现这样的操作.
[解决办法]
搜索一下 双缓冲
[解决办法]
起用窗体的双缓冲,用 graphics.drawstring画,把清除及移动操作放到 paint事件中
[解决办法]
闪是什么概念呢?是整个屏幕闪,整个form闪 还是只有lable闪?
lable闪是很正常的,无论用什么方法都要进行form的重新绘制
要想不闪,可以考虑根据文字生成动态gif图片,把图片放上去应该不闪吧:)