Scrolling (AutoScrollMinSize)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form {
[STAThread]
static void Main() {
Application.Run(new Form1());
}
protected override void OnPaint(PaintEventArgs e) {
Graphics g;
g = Graphics.FromHwnd(this.Handle);
GraphicsUnit units = GraphicsUnit.Pixel;
string path = "your.jpg";
Image im = Image.FromFile(path);
this.AutoScrollMinSize = new Size(im.Width, im.Height);
//this.AutoScroll = true;
Point P = this.AutoScrollPosition;
Rectangle dstR = this.ClientRectangle;
RectangleF srcR = new RectangleF(-P.X, -P.Y, dstR.Width, dstR.Height);
g.DrawImage(im, dstR, srcR, units);
g.Dispose();
}
}
Related examples in the same category