关闭

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

标签: floatobjectuser
4441人阅读 评论(0) 收藏 举报
分类:

        [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();

                }
            }
        }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:125332次
    • 积分:1564
    • 等级:
    • 排名:千里之外
    • 原创:31篇
    • 转载:7篇
    • 译文:0篇
    • 评论:11条
    文章分类
    最新评论