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

2019-02-18 06:53发布

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

2条回答
做自己的国王
2楼-- · 2019-02-18 07:19

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);
}
查看更多
登录 后发表回答