Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c中提升图片框上的鼠标滚轮事件#_C#_Winforms - Fatal编程技术网

C# 在c中提升图片框上的鼠标滚轮事件#

C# 在c中提升图片框上的鼠标滚轮事件#,c#,winforms,C#,Winforms,在看了,看了,看了,我已经编码了下面的片段,好吧。。。。不工作(即,鼠标滚轮在VS2013、Win7、x64中无法启动)。恳求任何帮助 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Drawing; namespace MyWin

在看了,看了,看了,我已经编码了下面的片段,好吧。。。。不工作(即,鼠标滚轮在VS2013、Win7、x64中无法启动)。恳求任何帮助

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;

namespace MyWinForm
{
    class Program
    {
        private Form theForm;
        private PictureBox thePictureBox;
        static void Main(string[] args)
        {

            Program theProgram = new Program();
            Application.Run(theProgram.theForm);

        }

        Program()
        {
            theForm = new Form();
            thePictureBox = new PictureBox();
            theForm.Controls.Add(thePictureBox);
            thePictureBox.Image = Image.FromFile(@"D:\cameraman.bmp");
            thePictureBox.Width = theImage.Width;
            thePictureBox.Height = theImage.Height;
            thePictureBox.MouseWheel += new MouseEventHandler(this.PictureBox_MouseWheel);
            thePictureBox.MouseHover += new EventHandler(this.PictureBox_MouseHover);

        }

        private void PictureBox_MouseWheel(object sender, MouseEventArgs e)
        {
            Console.WriteLine("2 + 2 = 5");//Will never get here....

        }
        private void PictureBox_MouseHover(object sender, EventArgs e)
        {
            thePictureBox.Focus();


        }
    }
}

使用mouseMove而不是mousehover对我有效:

        pictureBox1.MouseMove += newEventHandler(this.PictureBox_MouseHover);

现在只需将名称从“悬停”更改为“移动”即可:p

鼠标滚轮事件是鼠标中心事件。您必须滚动鼠标中心,然后将处理鼠标滚轮事件。

以防其他人正在寻找解决方案。 要生成pictureBox1 fire MouseWheel事件,我添加了一个MouseEnter事件:

private void pictureBox1_MouseEnter(object sender, EventArgs e)
    {
        pictureBox1.Focus();
    }

当我尝试时,您的代码运行得非常好。您是如何测试它的?Ctrl+F5->附加到进程->鼠标滚轮回调中的断点在将鼠标旋转到窗体上时不会被击中