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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 19:01:03  来源:igfitidea点击:

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

c#pictureboxmousewheelimage-zoom

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