Skip to content

User Control that enables zoom and pan in .NET windows forms

License

Notifications You must be signed in to change notification settings

AliAlAali/ZoomPanControl

Repository files navigation

ZoomPanControl

A user control written in c# for Windows Forms .NET environment, which supports zooming and panning.

How to use?

You can copy ZoomControl.cs to your project and start using the User Control right away! The following examples shows a quick demonstration on its use.

var Points = new List<PointF>() {
        new PointF(10, 10),
        new PointF(10, 80),
        new PointF(100, 40),
        new PointF(10, 10),
    };

    // Define handler painting
    zoomControl1.OnDraw += ZoomControl1_OnDraw;
    
    // Optional
    zoomControl1.MinZoom = 0.1f;
    zoomControl1.MaxZoom = 20f;
    zoomControl1.ZoomSensitivity = 0.2f;
    
    // Repaint control
    zoomControl1.Invalidate();
}

// Specify what to draw here using Graphics object
private void ZoomControl1_OnDraw(object sender, ZoomControl.DrawEventArgs e)
{
    var graphics = e.Graphics;
    var pen = new Pen(Color.Black);
    graphics.DrawLines(pen, Points.ToArray());
}

Control Keys

  • To zoom you must press ctrl + spin mouse wheel.
  • Pan hold shift + press mouse left button and drag the mouse.
  • To reset to the origin state press mouse button twice.

imageimage

License

Feel free to anything with this code.

About

User Control that enables zoom and pan in .NET windows forms

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages