Winforms 建议使用支持鼠标平移和缩放的Windows.Forms控件

Winforms 建议使用支持鼠标平移和缩放的Windows.Forms控件,winforms,scroll,mouse,panel,Winforms,Scroll,Mouse,Panel,我在中找到了自定义带有Autoscroll属性的面板,它是面板的包装,带有Autoscroll=True 我喜欢这个控件,因为它提供了“performScrollHorizontal”和“performScrollVertical”方法。但是,它使用Windows API函数而不是ScrollableControl及其VerticalScroll和HorizontalScroll属性 这是一个好的控件吗?我认为应该使用ScrollableControl而不是Windows API。你怎么认为?有

我在中找到了自定义带有Autoscroll属性的面板,它是
面板的包装,带有
Autoscroll=True

我喜欢这个控件,因为它提供了“performScrollHorizontal”和“performScrollVertical”方法。但是,它使用Windows API函数而不是
ScrollableControl
及其
VerticalScroll
HorizontalScroll
属性

这是一个好的控件吗?我认为应该使用
ScrollableControl
而不是Windows API。你怎么认为?有更好的控制吗?我需要控制吗?我认为
ScrollableControl
提供了我所需要的一切

编辑:我找到了HScrollBar和VScrollBar控件。我应该用它们吗

这两个其他控件很好,但没有像上面的控件那样为我提供控制滚动条的方法

  • 可滚动、可缩放和可缩放的图片框
  • 同时平移和缩放非常大的图像
我真正想要的是一个控件:

  • 当用户将鼠标移向控件边缘时滚动
  • 允许用户平移
  • 允许用户缩放
  • 支持在按住Shift键、Ctrl键或Alt键的情况下使用鼠标

非常感谢您提供的任何建议、帮助或关注的领域。控件会很好,因为我还不是很好。

一些代码可以玩。它支持焦点、平移和滚动。缩放是一项工作,我的笔记本电脑的鼠标垫妨碍了它的测试。使用计时器在边缘实现自动滚动

using System;
using System.Drawing;
using System.Windows.Forms;

class ZoomPanel : Panel {
    public ZoomPanel() {
        this.DoubleBuffered = true;
        this.SetStyle(ControlStyles.Selectable, true);
        this.SetStyle(ControlStyles.ResizeRedraw, true);
        this.AutoScroll = this.TabStop = true;
    }
    public Image Image {
        get { return mImage; }
        set { 
            mImage = value; 
            Invalidate();
            mZoom = 1.0;
            this.AutoScrollMinSize = (mImage != null) ? mImage.Size : Size.Empty;
        }
    }
    protected override void OnMouseDown(MouseEventArgs e) {
        if (e.Button == MouseButtons.Left) {
            this.Cursor = Cursors.SizeAll;
            mLastPos = e.Location;
            this.Focus();
        }
        base.OnMouseDown(e);
    }
    protected override void OnMouseUp(MouseEventArgs e) {
        if (e.Button == MouseButtons.Left) this.Cursor = Cursors.Default;
        base.OnMouseUp(e);
    }
    protected override void OnMouseMove(MouseEventArgs e) {
        if (e.Button == MouseButtons.Left) {
            this.AutoScrollPosition = new Point(
                -this.AutoScrollPosition.X - e.X + mLastPos.X,
                -this.AutoScrollPosition.Y - e.Y + mLastPos.Y);
            mLastPos = e.Location;
            Invalidate();
        }
        base.OnMouseMove(e);
    }
    protected override void OnMouseWheel(MouseEventArgs e) {
        if (mImage != null) {
            mZoom *= 1.0 + 0.3 * e.Delta / 120;
            this.AutoScrollMinSize = new Size((int)(mZoom * mImage.Width),
                (int)(mZoom * mImage.Height)); \
            // TODO: calculate new AutoScrollPosition...
            Invalidate();
        }
        base.OnMouseWheel(e);
    }
    protected override void OnPaint(PaintEventArgs e) {
        if (mImage != null) {
            var state = e.Graphics.Save();
            e.Graphics.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);
            e.Graphics.DrawImage(mImage, 
                new Rectangle(0, 0, this.AutoScrollMinSize.Width, this.AutoScrollMinSize.Height));
            e.Graphics.Restore(state);
        }
        //if (this.Focused) ControlPaint.DrawFocusRectangle(e.Graphics,
        //    new Rectangle(0, 0, this.ClientSize.Width, this.ClientSize.Height));
        base.OnPaint(e);
    }
    protected override void OnEnter(EventArgs e) { Invalidate(); base.OnEnter(e); }
    protected override void OnLeave(EventArgs e) { Invalidate(); base.OnLeave(e); }

    private double mZoom = 1.0;
    private Point mLastPos;
    private Image mImage;
}

我将如何使用计时器。我不知道从哪里开始。谢谢