C#进行Visio二次开发之图纸缩放操作的实现

我们知道,Visio菜单【视图】中有一个缩放的菜单项目,如下所示,选择响应的选项会对图纸进行缩放。
Visio_Zoom1.jpg

另外,它的工具条中也有一个下拉列表框,除了可以选择现有的那些选项外,还可以输入自定义的值,达到自定义缩放比例的功能。
Visio_Zoom2.jpg

本文介绍如何使用C#和Visio的SDK函数,实现Visio中的图纸各种缩放操作。
首先我们建立一个缩放菜单项和一个各种缩放比例的子菜单项,如第一个图形所示;然后将所有的子菜单项的事件处理指向同一个函数,如下所示
None.gif          private   void  menu_View_Zoom_Click( object  sender, EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            ToolStripMenuItem item 
= (ToolStripMenuItem)sender;
InBlock.gif            SetZoom(item.Text);
ExpandedBlockEnd.gif        }

然后添加下拉列表框,如第二个图形所示,并添加它的处理函数。
None.gif          private   void  tsStandard_Zoom_KeyUp( object  sender, KeyEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
if (e.KeyCode == Keys.Enter)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                SetZoom(tsStandard_Zoom.Text);
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }

接着我们实现SetZoom函数,该函数除了接收各种缩放比例外,还可以接收自定义的比例处理。
具体逻辑,看代码后就一目了然
None.gif          private   void  SetZoom( string  zoomText)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif
            switch (zoomText)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
case "400%":
InBlock.gif                    VisApplication.DoCmd((
short)VisUICmds.visCmdView400);
InBlock.gif                    
break;
InBlock.gif                
case "200%":
InBlock.gif                    VisApplication.DoCmd((
short)VisUICmds.visCmdView200);
InBlock.gif                    
break;
InBlock.gif                
case "150%":
InBlock.gif                    VisApplication.DoCmd((
short)VisUICmds.visCmdView150);
InBlock.gif                    
break;
InBlock.gif                
case "100%":
InBlock.gif                    VisApplication.DoCmd((
short)VisUICmds.visCmdView100);
InBlock.gif                    
break;
InBlock.gif                
case "75%":
InBlock.gif                    VisApplication.DoCmd((
short)VisUICmds.visCmdView75);
InBlock.gif                    
break;
InBlock.gif                
case "50%":
InBlock.gif                    VisApplication.DoCmd((
short)VisUICmds.visCmdView50);
InBlock.gif                    
break;
InBlock.gif                
case "上次":
InBlock.gif                    VisApplication.DoCmd((
short)VisUICmds.visCmdZoomLast);
InBlock.gif                    
break;
InBlock.gif                
case "宽度":
InBlock.gif                    VisApplication.DoCmd((
short)VisUICmds.visCmdZoomSingleTile);
InBlock.gif                    
break;
InBlock.gif                
case "":
InBlock.gif                    VisApplication.DoCmd((
short)VisUICmds.visCmdZoomPageWidth);
InBlock.gif                    
break;
InBlock.gif                
case "缩放dot.gif":
InBlock.gif                    VisApplication.DoCmd((
short)VisUICmds.visCmdViewCustom);
InBlock.gif                    
break;
InBlock.gif                
default:
InBlock.gif                    CustomedSize(zoomText);
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }

None.gif
None.gif        
private   void  CustomedSize( string  zoomText)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
double zoomSize = Convert.ToDouble(zoomText.Replace("%"""));
InBlock.gif                
this.VisWindow.Zoom = zoomSize / 100;
InBlock.gif                
this.tsStandard_Zoom.Text = zoomSize + "%";
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{ }
ExpandedBlockEnd.gif        }

这样就可以完整实现Visio中的缩放、自定义缩放等功能了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值