接著我們實現SetZoom函數,該函數除了接收各種縮放比例外,還可以接收自定義的比例處理。具體邏輯,看代碼後就一目了然
private void SetZoom(string zoomText)
{
switch (zoomText)
{
case "400%":
VisApplication.DoCmd((short)VisUICmds.visCmdVIEw400);
break;
case "200%":
VisApplication.DoCmd((short)VisUICmds.visCmdVIEw200);
break;
case "150%":
VisApplication.DoCmd((short)VisUICmds.visCmdVIEw150);
break;
case "100%":
VisApplication.DoCmd((short)VisUICmds.visCmdVIEw100);
break;
case "75%":
VisApplication.DoCmd((short)VisUICmds.visCmdVIEw75);
break;
case "50%":
VisApplication.DoCmd((short)VisUICmds.visCmdVIEw50);
break;
case "上次":
VisApplication.DoCmd((short)VisUICmds.visCmdZoomLast);
break;
case "寬度":
VisApplication.DoCmd((short)VisUICmds.visCmdZoomSingleTile);
break;
case "頁":
VisApplication.DoCmd((short)VisUICmds.visCmdZoomPageWidth);
break;
case "縮放":
VisApplication.DoCmd((short)VisUICmds.visCmdVIEwCustom);
break;
default:
CustomedSize(zoomText);
break;
}
}
private void CustomedSize(string zoomText)
{
try
{
double zoomSize = Convert.ToDouble(zoomText.Replace("%", ""));
this.VisWindow.Zoom = zoomSize / 100;
this.tsStandard_Zoom.Text = zoomSize + "%";
}
catch
{ }
}
這樣就可以完整實現Visio中的縮放、自定義縮放等功能了。