首页 > 解决方案 > 如何滚动缩放的图像C#

问题描述

我有一个图片框,我可以放大它。

当我缩放图片框时,我需要向左或向右滚动图像。

你能告诉我为什么当我缩放图像时,左侧是固定的,而我不能在左侧滚动吗?

我已经在主面板上激活了 AutoScroll,但我只能向右滚动,但我的图像居中,我也需要向左滚动。

我想要的是当您在 Win 10 中的照片应用程序内缩放和滚动图像时。但我使用的是 scoll 栏而不是鼠标指针。

结构如下图所示,主面板为红色,图片框为绿色。

在此处输入图像描述

    private void image_Scroll(object sender, EventArgs e)
    {
        int pbWidth = pbImg.Image.Width + (pbImg.Image.Width * ztb.Value / 100);
        int pbHeight = pbImg.Image.Height + (pbImg.Image.Height * ztb.Value / 100);

        int mpWidth =  mainPanel.Width:
        int mpHeight = mainPanel.Height;

        int pbX = (mpWidth - pbWidth) / 2;
        int pbY = (mpHeight - pbHeight) / 2;

        pbImg.Size = new Size(pbWidth, pbHeight);

        Point p = new Point(pbX, pbY);
        pictureBox.Location = p;
    }

标签: c#scrollbarzoomingpicturebox

解决方案


推荐阅读