using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace zoom_aug12
{
public partial class Form1 : Form
{
private Bitmap bmp;
Graphics grfbmp;
public Form1()
{
InitializeComponent();
bmp = new Bitmap(1000, 1000);
grfbmp = Graphics.FromImage(bmp);
Zoom =3F;
}
float _zoom = 1F;
public float Zoom
{
get
{
return _zoom;
}
set
{
_zoom = value;
UPDA();
}
}
public void UPDA()
{
this.AutoScrollMinSize = new Size((int)(bmp.Width*Zoom),(int)(bmp.Height*Zoom));
Refresh();
}
protected override void OnLoad(EventArgs e)
{
Rectangle rect = new Rectangle(0, 0, 999, 999);
Pen penblue = new Pen(Color.Blue);
grfbmp.DrawRectangle(penblue,rect);
base.OnLoad(e);
}
private Rectangle _drawrect = new Rectangle(0, 0, 1000, 1000);
public Rectangle DRAWRECT
{
get
{
return _drawrect;
}
set
{
_drawrect = value;
Refresh();
}
}
private PointF _viewportcenter;
PointF ViewPortCenter
{
get
{
return _viewportcenter;
}
set
{
_viewportcenter = value;
}
}
protected override void OnMouseWheel(MouseEventArgs e)
{
Zoom += Zoom * (e.Delta / 1200.0f);
if (e.Delta > 0)
ViewPortCenter = new PointF(ViewPortCenter.X + ((e.X - (Width / 2)) / (2 * Zoom)), ViewPortCenter.Y + ((e.Y - (Height / 2)) / (2 * Zoom)));
DRAWRECT = new Rectangle((int)ViewPortCenter.X,(int)(ViewPortCenter.Y),(int)(Width/Zoom),(int)(Height/Zoom));
//base.OnMouseWheel(e);
}
protected override void OnScroll(ScrollEventArgs se)
{
DRAWRECT = new Rectangle(0, 0, 1000, 1000);
base.OnScroll(se);
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(bmp, this.DisplayRectangle, DRAWRECT, GraphicsUnit.Pixel);
base.OnPaint(e);
}
}
}
This is my code.can any one please help me to fix the scroll bar accurately .using AutoScroll min size using C#
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).