本文介绍了如何删除鼠标输入事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



有没有办法简化这段代码。而不是启用和禁用图片框

pictureBox1.MouseEnter + = form_MouseClick;

pictureBox1.MouseEnter + = form_MouseClick;



请参阅代码。



我尝试过:



Hi everyone,

Is there a way to simplify this code. instead of enableing and disabling the pictureboxs
pictureBox1.MouseEnter += form_MouseClick;
pictureBox1.MouseEnter += form_MouseClick;

Please see the code.

What I have tried:

private void form_MouseClick(object sender, EventArgs e)
       {
           PictureBox picturebox = sender as PictureBox;
           SaveFileDialog savefile = new SaveFileDialog();
           savefile.Filter = @"Images|*.png";
           if (savefile.ShowDialog() == DialogResult.OK)
           {
               string filepath = Path.GetExtension(savefile.FileName);
               if (picturebox != null && filepath != null)
               {
                   Image image = picturebox.Image;
                   SaveImage(image, savefile.FileName);
               }
           }
           disable_clickevent();
       }
       private static void SaveImage(Image image, string destPath)
       {
           image.Save(destPath, System.Drawing.Imaging.ImageFormat.Png);
       }
       private void savaImageToolStripMenuItem_Click(object sender, EventArgs e)
       {
           pictureBox1.MouseEnter += form_MouseClick;
           pictureBox2.MouseEnter += form_MouseClick;
       }
       private void disable_clickevent()
       {
           pictureBox1.MouseEnter -= form_MouseClick;
           pictureBox2.MouseEnter -= form_MouseClick;
       }

推荐答案



这篇关于如何删除鼠标输入事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 12:17