在C#.net的图片框中使用鼠标滚动 [英] Use Mouse Scroll in Picture Box in C#.net

查看:56
本文介绍了在C#.net的图片框中使用鼠标滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


当用户将鼠标移至C#.net时,我想进行放大和缩小.这是Windows应用程序.请帮助我.

Hi,
i want to Zoom In and Zoom Out when user mouse wheel in the C#.net. It is an Windows Application . Please Help me.

推荐答案

就像格里夫(Griff)在他的解决方案中所说的
Just as Griff said in his solution
Quote:

PictureBox永远无法获得输入焦点[...]

The PictureBox can never have the input focus[...]



但我试着爱管闲事:



But nosy as I am I tried this:

pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);
pictureBox1.MouseHover += new EventHandler(pictureBox1_MouseHover);

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


void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
{
    // here I can use e.Delta        
}



在使用MouseHover获取焦点时,没有检查陷阱.只是一个主意...



Did not check for pitfalls in using MouseHover to get focus. Just an idea...


您不能不钩上MouseWheel消息.

您可以为事件添加一个处理程序(通过在表单加载事件处理程序中编写代码-它在设计器中被屏蔽),但是它永远不会发生.原因? PictureBox永远不会拥有输入焦点,因此永远不会服从鼠标滚轮命令.因此,设计器中没有事件,应用程序运行时也没有事件.
尝试以下操作:添加一个面板,并为其提供MouseWheel处理程序.使其打印到控制台.试试吧.什么都没发生.
在面板上添加一个文本框.再试一次.当文本框具有焦点时,您将获得鼠标滚轮事件.

尝试想出另一种缩放方法,它会容易得多!
You can''t, without hooking the MouseWheel messages.

You can add a handler for the event (by writing the code in your form load event handler - it is masked in the designer) but it will never occur. The reason? The PictureBox can never have the input focus, so can never obey mouse wheel commands. So, no event in the designer, no event when the app runs.
Try this: Add a panel, and give it a MouseWheel handler. Make it print to the console. Try it. Nothing happens.
Add a textbox to the panel. Try again. When the textbox has the focus, you get mouse wheel events.

Try and think of another way to do your zoom, it will be much easier!


这篇关于在C#.net的图片框中使用鼠标滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆