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

。关于重绘的有关问题

2012-04-12 
求助。关于重绘的问题我做了个小东西private void button2_Click(object sender, EventArgs e){Bitmap bmp

求助。关于重绘的问题
我做了个小东西

private void button2_Click(object sender, EventArgs e)
  {
  Bitmap bmp = new Bitmap(this.pictureBox1.ClientRectangle.Width, this.pictureBox1.ClientRectangle.Height);
  Graphics g = Graphics.FromImage(bmp);
  g.Clear(Color.Black);
  g.DrawRectangle(new Pen(Color.Red), 10, 10, 40, 20);
  g.Dispose();
  this.pictureBox1.Image = bmp;
  }
类似的吧。。。
然后呢。我想在pictureBox里先添加个图片再进行操作。
但是,执行上面的代码后,出现原来的图片没了,只有上面的操作了。去解决方法

[解决办法]
你将原来的清除了,试试下面的
private void button1_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(pictureBox1.Image);
Graphics g = Graphics.FromImage(bmp);
g.DrawRectangle(new Pen(Color.Red), 10, 10, 40, 20);
g.Dispose();
this.pictureBox1.Image = bmp; 
}

热点排行