pictureBox里用滚轮实现 放大缩小功能

        [DllImport("user32.dll")]
        public static extern int WindowFromPoint(int xPoint, int yPoint);

        void Form1_MouseWheel(object sender, MouseEventArgs e)
        {
            System.Drawing.Point p = PointToScreen(e.Location);
            if (WindowFromPoint(p.X, p.Y) == pictureBox1.Handle.ToInt32())
            {

                //向前
                if (e.Delta > 0)
                {
                    float w = this.pictureBox1.Width * 0.9f; //每次縮小 20%  
                    float h = this.pictureBox1.Height * 0.9f;
                    this.pictureBox1.Size = Size.Ceiling(new SizeF(w, h));

                }

                //向后
                else if (e.Delta < 0)
                {

                    float w = this.pictureBox1.Width * 1.1f; //每次放大 20%
                    float h = this.pictureBox1.Height * 1.1f;
                    this.pictureBox1.Size = Size.Ceiling(new SizeF(w, h));
                    pictureBox1.Invalidate();

                }
            }
        }

你可能感兴趣的:(object,user,float)