c# - 如何在c#中使用鼠标滚轮放大和缩小图片框中的图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11734934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to zoom-in and zoom-out a image in picturebox using mouse wheels in c#?
提问by Praveen Kumar
I want to zoom-in or zoom-out a image on picturebox using mouse wheels in c#.How Can i do?
我想在 c# 中使用鼠标滚轮放大或缩小图片框上的图像。我该怎么做?
回答by mathieu
Use the MouseWheel event : http://msdn.microsoft.com/fr-fr/library/system.windows.forms.control.mousewheel%28v=vs.80%29
使用 MouseWheel 事件:http: //msdn.microsoft.com/fr-fr/library/system.windows.forms.control.mousewheel%28v=vs.80%29
回答by Sivodaya Tech
This topic helps to zoom in and out picture in picturebox
本主题有助于放大和缩小图片框中的图片
add below code inside the picturebox mouse wheel event
在图片框鼠标滚轮事件中添加以下代码
if (e.Delta != 0) {
if (e.Delta <= 0) {
//set minimum size to zoom
if (PictureBox1.Width < 50)
return;
} else {
//set maximum size to zoom
if (PictureBox1.Width > 500)
return;
}
PictureBox1.Width += Convert.ToInt32(PictureBox1.Width * e.Delta / 1000);
PictureBox1.Height += Convert.ToInt32(PictureBox1.Height * e.Delta / 1000);
}

