首页新闻找找看学习计划

如何用C#实现windows中画图软件的放大缩小功能?

0
悬赏园豆:5 [已解决问题] 解决于 2019-09-10 14:21

放大缩小时里面的元素保持位置(比列不变)

搬砖的L先生的主页 搬砖的L先生 | 初学一级 | 园豆:24
提问于:2019-09-09 13:41
< >
分享
最佳答案
0

注册滚轮事件:panel1.MouseWheel += PictureBox1OnMouseWheel;
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;

    private void PictureBox1OnMouseWheel(object sender, MouseEventArgs e)
    {
        double step = 1.2; //缩放倍率
        if (e.Delta > 0)
        {
            pictureBox1.Height = (int) (pictureBox1.Height * step);
            pictureBox1.Width = (int) (pictureBox1.Width * step);

            int px = e.X - pictureBox1.Location.X;
            int py = e.Y - pictureBox1.Location.Y;
            int pxAdd = (int) (px * (step - 1.0));
            int pyAdd = (int) (py * (step - 1.0));
            pictureBox1.Location = new Point(pictureBox1.Location.X - pxAdd, pictureBox1.Location.Y - pyAdd);
        }
        else
        {
            pictureBox1.Height = (int) (pictureBox1.Height / step);
            pictureBox1.Width = (int) (pictureBox1.Width / step);

            int px = e.X - pictureBox1.Location.X;
            int py = e.Y - pictureBox1.Location.Y;
            int pxAdd = (int) (px * (1.0 - 1.0 / step));
            int pyAdd = (int) (py * (1.0 - 1.0 / step));
            pictureBox1.Location = new Point(pictureBox1.Location.X + pxAdd, pictureBox1.Location.Y + pyAdd);
        }
    }
收获园豆:5
张朋举 | 小虾三级 |园豆:1727 | 2019-09-09 21:33

如果这张图片为图层,我在这上面绘制了很多东西,可以选中移动得那种,如何缩放得时候保持位置不变

搬砖的L先生 | 园豆:24 (初学一级) | 2019-09-10 16:35
其他回答(1)
0

panel里放个picturebox,加上滚轮事件

jqw2009 | 园豆:1911 (小虾三级) | 2019-09-10 14:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册