How to zoom-in and zoom-out a image in picturebox using mouse wheels in c#?

白昼怎懂夜的黑 提交于 2019-12-01 04:20:45

问题


I want to zoom-in or zoom-out a image on picturebox using mouse wheels in c#.How Can i do?


回答1:


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);
}



回答2:


Use the MouseWheel event : http://msdn.microsoft.com/fr-fr/library/system.windows.forms.control.mousewheel%28v=vs.80%29



来源:https://stackoverflow.com/questions/11734934/how-to-zoom-in-and-zoom-out-a-image-in-picturebox-using-mouse-wheels-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!