图片的放大我们应该明确的是:图片在PictureBox中,我们放大的实际上上PictureBox本身。

        PictureBox需要设置如下:

           1、SizeMode:Zoom

        PictureBox所在的容器控件:

           2、AutoScroll:True    


    添加鼠标滚轮事件:


       this.pictureBox1.MouseWheel += new MouseEventHandler(PictureBox1_MouseWheel);    


        private bool isMove = false;
        private Point mousePos;
        
        private void PictureBox1_MouseDown(object sender, MouseEventArgs e)
        { 
            this.pictureBox1.Focus(); 
            isMove = true;
            mousePos = new Point(e.X, e.Y); 
        }
        
        private void PictureBox1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
        { 
            if (e.Delta > 0) {
                this.pictureBox1.Width = this.pictureBox1.Width * 9 / 10;
                this.pictureBox1.Height = this.pictureBox1.Height * 9 / 10;
            } else {
                this.pictureBox1.Width = this.pictureBox1.Width * 11 / 10;
                this.pictureBox1.Height = this.pictureBox1.Height * 11 / 10;
            }
        }
        
        void PictureBox1MouseUp(object sender, MouseEventArgs e)
        {
            this.isMove = false;  
        }


        void PictureBox1MouseMove(object sender, MouseEventArgs e)
        {
            if (this.isMove) {
                if ((pictureBox1.Location.Y
                     - mousePos.Y + e.Y) > 0 && (pictureBox1.Location.X
                    - mousePos.X + e.X)>0) {
                    pictureBox1.Location = new Point(pictureBox1.Location.X
                    - mousePos.X + e.X, pictureBox1.Location.Y
                    - mousePos.Y + e.Y);
                }
            }   
        }


WinForm中图片的拖动及滚轮调整其放大与缩写,防止图片超出范围_第1张图片