110,561
社区成员
发帖
与我相关
我的任务
分享
public void DrawZoomIn()
{
scale = scale / ampfactor;
Point pt = GetDisplayCenter();//获取当前显示中心
int iwidth = (int)(Width / ampfactor);//ampfactor是放大系数
int iheight = (int)(Height / ampfactor);
//对长和宽进行长度限制
if (iwidth > 7000 || iheight > 7000)
{
scale = scale * ampfactor;
return;
}
this.Size = new Size(iwidth, iheight);
//对滚动条进行控制
if (iwidth >= rcclient.Width)
{
pt.X = (int)(pt.X / ampfactor - rcclient.Width / 2);
pt.Y = (int)(pt.Y / ampfactor - rcclient.Height / 2);
owner.AutoScrollPosition = pt;//owner为control的容器panel panel的autoscroll属性为true
}
}
private void DrawArea_Paint(object sender, PaintEventArgs e)
{
if (e.ClipRectangle.Width == 0 || e.ClipRectangle.Height == 0)
{
return;
}
DrawGrid(e.Graphics);//绘制网格
_graphicsList.Draw(e.Graphics,scale,ClientRectangle);//绘制保存的矩形、线等
}
this.SetStyle(ControlStyles.OptimizedDoubleBuffer
| ControlStyles.ResizeRedraw
| ControlStyles.Selectable
| ControlStyles.AllPaintingInWmPaint
| ControlStyles.UserPaint
| ControlStyles.SupportsTransparentBackColor,
true);
this.UpdateStyles();