首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

picturebox控件无法刷新解决办法

2012-02-29 
picturebox控件无法刷新由于显示动态图形的闪烁问题,采用以下方法:Dim bmp As Bitmap New Bitmap(1050,

picturebox控件无法刷新
由于显示动态图形的闪烁问题,采用以下方法:
  Dim bmp As Bitmap = New Bitmap(1050, 300)
  Dim g As Graphics
  Dim pen1 As System.Drawing.Pen
  g = Graphics.FromImage(bmp)
  pen1 = New System.Drawing.Pen(Color.Green, 2)

循环开始
。。。
之间是x y的赋值
。。。

  g.DrawLine(pen1, x1, y1, x2, y2)
  PictureBox1.Image = bmp

循环结束

结果画出来的图形全部叠加在一起,我要的是每画一次图形显示在picturebox上且下次显示时消除上一次的显示的图形
picturebox.Refresh() 不起作用
.dispose()也不好使

求高手解答



[解决办法]

C# code
private void button1_Click(object sender, EventArgs e)        {            Bitmap bmp = new Bitmap(400, 300);            Graphics g = Graphics.FromImage(bmp);            Pen pen1 = new Pen(Color.Green, 2);            for (int i = 0; i < 100; i++)            {                g.Clear(pictureBox1.BackColor);                g.DrawLine(pen1, i, 0, i, i);            }            pictureBox1.Image = bmp;        }
[解决办法]
C# code
public partial class Form1 : Form    {        public int x = 50;        public int y = 0;        public Form1()        {            InitializeComponent();        }        private void Form1_Load(object sender, EventArgs e)        {        }        private void button1_Click(object sender, EventArgs e)        {            timer1.Enabled = true;        }        private void timer1_Tick(object sender, EventArgs e)        {            x--;            y++;            Bitmap bmp = new Bitmap(400, 300);            Graphics g = Graphics.FromImage(bmp);            Pen pen1 = new Pen(Color.Green, 2);            g.Clear(pictureBox1.BackColor);            g.DrawLine(pen1, 0, 0, x, y);            pictureBox1.Image = bmp;        }    } 

热点排行