-->

How to zoom-in and zoom-out a image in picturebox

2019-02-18 06:57发布

问题:

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