日期:2014-05-17  浏览次数:20798 次

如何在keydown事件里面调用paint事件
或者,在paint的事件里面使用keydown的判断,如何用,求高手!

------解决方案--------------------
 KeyDown += (ss, ee) =>
            {
                if (ee.KeyCode == Keys.C)
                {
                    MessageBox.Show(ee.KeyValue + "");
                }
            };

------解决方案--------------------
你可以把绘图的代码写在方法中,再在keydown事件里面调用这个方法呗

 public void refreshImg(Image image)
 {
     Bitmap bufferBmp = (Bitmap)image;//new Bitmap(200, 200);   //创建位图缓冲区
     Graphics g = this.panel1.CreateGraphics();                 //创建窗体图形

     Pen pen = new Pen(Color.Red);
     Graphics buf_g = Graphics.FromImage(bufferBmp);

     buf_g.Dispose();                //绘画已完成,释放掉buf_g
     g.DrawImage(bufferBmp, 0, 0);   //将bufferBmp中的内容画到屏幕上
  }

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.A)
    {
      Image img = null; 
      refreshImg(img);
    }
}