c# 如何打开和关闭Visio文件 C#做Visio二次开发时如何关闭形状窗口(望有代码。。)

\u600e\u4e48\u6253\u5f00visio\u6587\u4ef6

1\u3001\u9996\u5148\u9700\u786e\u4fdd\u7535\u8111\u5b89\u88c5\u6709Microsoft visio 2010\uff0c\u7136\u540e\u4ece\u7535\u8111\u5de6\u4e0b\u89d2\u7684\u5f00\u59cb\u4e2d\u6253\u5f00\u5df2\u7ecf\u5b89\u88c5\u597d\u7684viso\u7684\u8f6f\u4ef6\u3002

2\u3001\u8fdb\u884c\u70b9\u51fb\u5de6\u4e0a\u89d2\u4e2d\u7684 \u6587\u4ef6 \u83dc\u5355\u9009\u9879\u3002

3\u3001\u8fdb\u884c\u70b9\u51fb\u4e86\u6587\u4ef6 \u7684\u83dc\u5355\u4e4b\u540e\uff0c\u5f39\u51fa\u4e86\u4e0b\u4e00\u7ea7\u83dc\u5355\u9009\u4e2d\u4e3a \u6253\u5f00 \u7684\u9009\u9879\u3002

4\u3001\u8fdb\u884c\u70b9\u51fb\u6253\u5f00\u4e4b\u540e\uff0c\u5f39\u51fa\u4e86\u7684\u7535\u8111\u7684\u7a97\u53e3\u7684\u754c\u9762\u5f53\u4e2d\uff0c\u8fdb\u884c\u9009\u4e2dvsd\u7684\u9009\u9879\u3002

5\u3001\u9009\u4e2d\u4e86\u4e00\u4e2a\u6587\u4ef6\u4e4b\u540e\uff0c\u8fdb\u884c\u70b9\u51fb \u6253\u5f00 \u7684\u9009\u9879\u3002

6\u3001visio\u6587\u4ef6\u5df2\u7ecf\u88ab\u6253\u5f00\u4e86\u3002

\u4f60\u597d\uff0c\u6211\u60f3\u8ddf\u4f60\u4ea4\u6d41\u4ea4\u6d41\u8fd9\u4e2a\u65b9\u9762\u7684\u77e5\u8bc6\u3002

\u80fd\u7559\u4e2a\u65b9\u5f0f\u5417\uff1f

\u6211\u60f3\u5f00\u53d1\u4e00\u4e2a\u7c7b\u4f3cvisio\u7684\u4e1c\u897f\uff0c\u7528\u6765\u505a\u7efc\u5408\u5e03\u7ebf\u7cfb\u7edf\u3002

\u6bd4\u5982\uff0c\u5f80\u754c\u9762\u62fd\u4e00\u4e2a\u4ea4\u6362\u673a\uff0c\u7136\u540e\u518d\u62fd\u51e0\u53f0\u7535\u8111\uff0c\u53ef\u4ee5\u5bf9\u5b83\u4eec\u8fde\u7ebf\u3002

Visio Drawing Control控件使用
Visio开发必备
Visio SDK 2007
VisSDK.chm
Visio Code Samples Library.chm
Visio文档操作
查看ShapeSheet属性及帮助内容
宏的录制

Visio的几个重要对象

Application
Window (Application.ActiveWindow)
Document (Application.ActiveDocument)
Master、Shape

Visio XML格式文件分析
Master格式

Pages/Shapes格式

图纸的XML文档中,Master后面的Shapes集合中只有一个Shape对象
图纸的Shapes集合有多个对象,每个对象的NameU和Name值可能不一样,一般使用NameU

Visio基本操作的实现

VisApplication = this.ctrlDrawing.Document.Application;
VisWindow = VisApplication.ActiveWindow;
VisDocument = VisApplication.ActiveDocument;

//Settings
VisApplication.Settings.ShowShapeSearchPane = false; //显示搜索形状窗体
VisApplication.Settings.EnableAutoConnect = false; //自动链接(2007默认)
VisApplication.Settings.StencilBackgroundColor = 10070188; //vbGrayText

//文档各种显示
VisApplication.DoCmd((short)VisUICmds.visCmdViewRulers);
VisApplication.DoCmd((short)VisUICmds.visCmdViewGrid);
VisApplication.DoCmd((short)VisUICmds.ShowGuides);
VisApplication.DoCmd((short)VisUICmds.ShowConnectPoints);
VisApplication.DoCmd((short)VisUICmds.ShowPageBreaks);

//各种窗口
VisApplication.DoCmd((short)VisUICmds.visCmdShapesWindow);
VisApplication.DoCmd((short)VisUICmds.visCmdPanZoom);
VisApplication.DoCmd((short)VisUICmds.visCmdCustProp);
VisApplication.DoCmd((short)VisUICmds.visCmdSizePos);

SendKeys.Send("^(x)");
//VisApplication.DoCmd((short)VisUICmds.visCmdUFEditCut);
SendKeys.Send("{DELETE}");
//VisApplication.DoCmd((short)VisUICmds.visCmdUFEditClear);
SendKeys.Send("^+(p)");
//VisApplication.DoCmd(VisUICmds.visCmdFormatPainter);
SendKeys.Send("^(z)");
//VisApplication.DoCmd(VisUICmds.visCmdEditUndo);
调用工具条对象、菜单对象的方法
Application.CommandBars
Microsoft.Office.Core.CommandBars共享Office对象模型
使用CommandBar代替UIObject
CommandBar对象中,菜单及工具条是同一个东西
CommandBar、CommandBarButton、 CommandBarComboBox、CommandBarControl、 和 CommandBarPopup

示例:执行视图中的工具条的所有按钮事件。
Microsoft.Office.Core.CommandBars commandBars;
commandBars = (Microsoft.Office.Core.CommandBars)VisApplication.CommandBars;

foreach (Microsoft.Office.Core.CommandBarControl control in commandBars["View"].Controls)
{
Microsoft.Office.Core.CommandBarButton button = control as Microsoft.Office.Core.CommandBarButton;
if (button != null)
{
button.Execute();
}
}

StringBuilder sb = new StringBuilder();
foreach (Microsoft.Office.Core.CommandBar bar in commandBars)
{
sb.Append(string.Format("CommandBar Name:{0}\r\n", bar.Name));
foreach(Microsoft.Office.Core.CommandBarControl control in bar.Controls)
{
Microsoft.Office.Core.CommandBarButton button = control as Microsoft.Office.Core.CommandBarButton;
if(button != null)
{
sb.Append(string.Format("Button Name:{0} \r\n", button.Caption));
}
}
}
Form2 frm = new Form2();
frm.txtContent.Text = sb.ToString();
frm.Show();

short flags = (short)VisOpenSaveArgs.visOpenDocked | (short)VisOpenSaveArgs.visOpenRO;
StencilOpenEx(wndVisio.Application, flags);

/**//// <summary>
/// 打开模具的公共方法
/// </summary>
/// <param name="visApp">按引用调用的VisioApplication对象</param>
/// <param name="flags">打开的模式</param>
private void StencilOpenEx(Application visApp, short flags)
{
List<string>stencilList = GetStencils();
string stencilFileName;

foreach(string stencil in stencilList)
{
stencilFileName = GetStencilsFileName(stencil);
if(!string.IsNullOrEmpty(stencilFileName))
{
visApp.Documents.OpenEx(Portal.gc.gStencileFileBasePath + stencilFileName, flags);
}
}
}

//关闭模具文件
visApp.Documents["Switch.vss"].Close();
visApp.Documents["Span.vss"].Close();
visApp.Documents["Line.vss"].Close();
visApp.Documents["Label.vss"].Close();
visApp.Documents["Construct.vss"].Close();
visApp.Documents["Monitor.vss"].Close();

Visio Shape的属性操作
StringToFormulaForString、FormulaStringToString函数
访问属性
设置属性
添加属性

//列出模具组
this.cmbStencilGroup.Items.Clear();
List<string>stencilGroups = stencil.GetStencils();
foreach (string group in stencilGroups)
{
this.cmbStencilGroup.Items.Add(group);
}

//根据模具组列出模具
string stencilName = stencil.GetStencilsFileName(this.cmbStencilGroup.Text);
this.cmbStencil.Items.Clear();
string tempName;
foreach (Master master in visApp.Documents[stencilName].Masters)
{
tempName = master.Name;
if (!stencil.IsExcludeItem(tempName))
{
this.cmbStencil.Items.Add(tempName);
}
}

//根据模具,获取对应的属性集合,遍历属性集合,列出属性名称
string stencilName = stencil.GetStencilsFileName(this.cmbStencilGroup.Text);
string masterName = this.cmbStencil.Text;
Visio.Shape shape = visApp.Documents[stencilName].Masters[masterName].Shapes[1];
if (shape != null)
{
List<StencilPropertyInfo>propInfos = property.GetPropertyCollection(shape);
foreach (StencilPropertyInfo info in propInfos)
{
this.cmbProperty.Items.Add(info.Name);
}
}

//根据模具、模具属性,列出对应的属性信息
string stencilName = stencil.GetStencilsFileName(this.cmbStencilGroup.Text);
string masterName = this.cmbStencil.Text;
Visio.Shape shape = visApp.Documents[stencilName].Masters[masterName].Shapes[1];
StencilPropertyInfo info = property.GetProperty(shape, this.cmbProperty.Text);
if (info != null)
{
this.txtName.Text = info.Name; //属性名称
this.txtValue.Text = info.Value; //属性值
this.txtFormat.Text = info.Format; //属性格式
this.txtSortKey.Text = info.Sort; //属性的排序
this.txtPrompt.Text = info.Prompt; //属性的提示信息
}

//根据模具,获取属性对象集合
public List<StencilPropertyInfo> GetPropertyCollection(Visio.Shape shape)
{
List<StencilPropertyInfo> list = new List<StencilPropertyInfo>();
StencilPropertyInfo propertyInfo;
Visio.Cell shapeCell;
short shortSectionProp = (short)VisSectionIndices.visSectionProp;

if (shape != null)
{
for (short i = 0; i < shape.get_RowCount(shortSectionProp) - 1; i++ )
{
if (shape.get_CellsSRCExists(shortSectionProp, i, (short)VisCellIndices.visCustPropsLabel, 0) != 0)
{
propertyInfo = new StencilPropertyInfo();

shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsLabel);
propertyInfo.Name = VisioUtility.FormulaStringToString(shapeCell.RowNameU);

shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsPrompt);
propertyInfo.Prompt = VisioUtility.FormulaStringToString(shapeCell.FormulaU);

shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsFormat);
propertyInfo.Format = VisioUtility.FormulaStringToString(shapeCell.FormulaU);

shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsValue);
propertyInfo.Value = VisioUtility.FormulaStringToString(shapeCell.FormulaU);

shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsSortKey);
propertyInfo.Sort = VisioUtility.FormulaStringToString(shapeCell.FormulaU);

//shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsType);
//propertyInfo.PropType = VisioUtility.FormulaStringToString(shapeCell.FormulaU);

//shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsInvis);
//propertyInfo.InVisible = VisioUtility.FormulaStringToString(shapeCell.FormulaU);
//..
list.Add(propertyInfo);
}
}
}

return list;
}

//根据模具和属性名称,获取属性对象信息
public StencilPropertyInfo GetProperty(Visio.Shape shape, string propertyName)
{
List<StencilPropertyInfo> list = GetPropertyCollection(shape);
StencilPropertyInfo propertyInfo = null;
foreach(StencilPropertyInfo tempInfo in list)
{
if (tempInfo.Name == propertyName)
{
propertyInfo = tempInfo;
break;
}
}

return propertyInfo;
}
=====
我也没有写过visio操作,这个是收藏的代码,没有帮到你hoho,你可以去CSDN里面发帖求助一下

  • c鏄粈涔堟剰鎬
    绛旓細c++鐨勫叿浣撳惈涔夊涓嬶細C++鏄C璇█鐨勭户鎵匡紝瀹冩棦鍙互杩涜C璇█鐨勮繃绋嬪寲绋嬪簭璁捐锛屽張鍙互杩涜浠ユ娊璞℃暟鎹被鍨嬩负鐗圭偣鐨勫熀浜庡璞$殑绋嬪簭璁捐锛岃繕鍙互杩涜浠ョ户鎵垮拰澶氭佷负鐗圭偣鐨勯潰鍚戝璞$殑绋嬪簭璁捐銆侰++鎿呴暱闈㈠悜瀵硅薄绋嬪簭璁捐鐨勫悓鏃讹紝杩樺彲浠ヨ繘琛屽熀浜庤繃绋嬬殑绋嬪簭璁捐锛屽洜鑰孋++灏遍傚簲鐨勯棶棰樿妯¤岃锛屽ぇ灏忕敱涔嬨侰++涓嶄粎鎷ユ湁...
  • c鐨勫叕寮忔槸浠涔?
    绛旓細m>n銆傛帓鍒楃粍鍚c鐨勫叕寮忥細C(n,m)=A(n,m)/m!=n!/m!(n-m)!涓嶤(n,m)=C(n,n-m)銆(n涓轰笅鏍,m涓轰笂鏍)銆備緥濡侰(4,2)=4!/(2!*2!)=4*3/(2*1)=6,C(5,2)=C(5,3)銆傛帓鍒楃粍鍚坈璁$畻鏂规硶锛欳鏄粠鍑犱釜涓夊彇鍑烘潵锛屼笉鎺掑垪锛屽彧缁勫悎銆侰(n锛宮)=n*(n-1)*...*(n-m+1)/m...
  • C鏄粈涔堟剰鎬?
    绛旓細C琛ㄧず缁勫悎鏁般侰(n,m) 琛ㄧずn閫塵鐨勭粍鍚堟暟锛屽叾涓璶鏄笅鏍 , m鏄笂鏍 (C涓婇潰m,涓嬮潰n)銆俷Ck鏄竴涓暣浣擄紝鏄痭涓厓绱犱腑锛屽彇k涓厓绱犵殑鍙栨硶鐨勪釜鏁帮紝涔熷彨n涓厓绱犱腑锛屽彇k 涓猭缁勫悎鏁帮紝锛圕浠h〃缁勫悎锛夛紝绠楁硶鏄細nCk锛漬!/k!锛坣-k锛!锛漬锛坣-1锛夆︹︼紙n-k+1锛/k!绛変簬浠巒寮濮嬭繛缁掑噺鐨刴涓嚜鐒...
  • c鐨勬剰鎬?
    绛旓細C鏄彂鐢熶簨鏁呯殑涓ラ噸鎬э紝consequences鐨勭缉鍐欍俢onsequences 鑻 ['k蓱nsə,kwɛnsɪz] 缇 ['k蓱nsə,kwɛnsɪz]n. 鍚庢灉锛岀粨鏋滐紱褰卞搷锛坈onsequence鐨勫鏁帮級鐭锛歶nintended consequences 鎰忓鍚庢灉 ; 闈為鏈熷悗鏋 ; 鏈鏈熺殑鍚庢灉 ; 娌℃湁棰勮鐨勭粨鏋 serious consequences...
  • C鐨勫惈涔夋槸浠涔?
    绛旓細鏁板绗﹀彿c鍙充笂瑙掓槸1鍙充笅瑙掓槸4鐨勬剰鎬濇槸鏁板涓殑缁勫悎锛屽彸涓嬭鐨4琛ㄧず鎬讳綋涓暟锛屽彸涓婅鐨1琛ㄧず鎶藉彇涓暟锛屼笖浠4涓噷闈㈡娊鍙栦竴涓紝C¹₄=4梅1=4銆傜粍鍚堬細涓鑸湴锛屼粠n涓笉鍚岀殑鍏冪礌涓紝浠诲彇m锛坢鈮锛変釜鍏冪礌涓轰竴缁勶紝鍙綔浠巒涓笉鍚屽厓绱犱腑鍙栧嚭m涓厓绱犵殑涓涓粍鍚堛傛墍鏈夎繖鏍风殑缁勫悎鐨勬绘暟...
  • c鍦ㄧ埍鎯呯殑鍚箟鏄粈涔
    绛旓細c鍦ㄧ埍鎯呯殑鍚箟鏄粈涔,鐢ㄥ悇绉嶅悇鏍风殑绗﹀彿鏉ヤ唬鏇挎垜浠兂瑕佽〃杈剧殑鐪熷疄鎰忔濇槸鎴戜滑瀵逛竴浠芥劅鎯呯殑鍚搫琛ㄧず,涓栭棿涓囩墿瀛樺湪鐨勬剰涔夊氨鏄垜浠祴浜堢殑鍐呮兜,涓嬮潰鍒嗕韩c鍦ㄧ埍鎯呯殑鍚箟鏄粈涔堛 c鍦ㄧ埍鎯呯殑鍚箟鏄粈涔1 C鎸囩殑鏄幇鍦ㄦ祦琛岀殑C鍨嬬埍鎯呰銆 C鍨嬬埍鎯呰 鈥淐鍨嬬埍鎯呰鈥濇寚鐨勬槸瀵圭幇浠g埍鎯呭叧涓绉嶆柊鐨勫畾涔夈傚湪鐖辨儏涓,鏈夎繘鏈夐銆...
  • C璇█鍜孋++鏈変粈涔堝尯鍒?
    绛旓細涓銆佷富浣撲笉鍚 1銆C璇█锛氭槸涓闂ㄩ潰鍚戣繃绋嬬殑銆佹娊璞″寲鐨勯氱敤绋嬪簭璁捐璇█锛屽箍娉涘簲鐢ㄤ簬搴曞眰寮鍙戙2銆丆++锛氭槸C璇█鐨勭户鎵匡紝瀹冩棦鍙互杩涜C璇█鐨勮繃绋嬪寲绋嬪簭璁捐锛屽張鍙互杩涜浠ユ娊璞℃暟鎹被鍨嬩负鐗圭偣鐨勫熀浜庡璞$殑绋嬪簭璁捐銆備簩銆佷紭鍔夸笉鍚 1銆丆璇█锛氳兘浠ョ畝鏄撶殑鏂瑰紡缂栬瘧銆佸鐞嗕綆绾у瓨鍌ㄥ櫒銆侰璇█鏄粎浜х敓灏戦噺鐨勬満鍣...
  • c寮澶存槸浠涔堣溅
    绛旓細C瀛楀ご鐨勫垪杞︽槸鍩庨檯鍔ㄨ溅缁勫垪杞︺傚煄闄呭垪杞︼紝鍙堢О鍩庨檯涓撳垪锛圛nter-City Rail Service锛夛紝鏄寚寰杩斾簬鐩搁偦閲嶈鍩庡競鎴栧煄甯傜兢涔嬮棿鐨勫杩愬垪杞︼紝涓鑸叏绋嬭繍琛岃窛绂昏緝杩戙佷箻杞︽椂闂磋緝鐭侀旂粡鍩庡競杈冨皯锛屼笉閰嶇疆鍗ч摵杞﹀帰銆傚拰璋愬彿鍔ㄨ溅鐨勮溅鍨嬶紝鐢卞師鏉ョ殑鍔ㄨ溅鍨嬪彿D鏀逛负C,骞跺皢鍏跺懡鍚嶄负鍩庨檯杞昏建銆 (G瀛楀ご杞︽鏄寚楂橀搧)楂橀搧...
  • c鏄粈涔堣溅鏍
    绛旓細琛屾斂绾у埆鐨勮娇杞C杞︼紝鎴栫О涓 Execuive锛屼篃灏辨槸琛屾斂绾у埆鐨勮娇杞︼紝鎺掗噺涓鑸槸2.4鍒3.2鍗囷紝杩欎釜绾ц溅鐨勬帓姘旈噺鍙珮鍙綆銆傞氬父鏈 A銆 B銆 C銆 D绛夌骇杞︼紝鍚勫浗鏍囧噯涓嶅悓锛屾垜鍥芥洿娌℃湁缁熶竴鐨勬爣鍑嗭紝鍥犱负寰峰浗姹借溅棣栧厛涓庢垜鍥藉悎璧勫苟鍗犻浜嗕竴瀹氬競鍦猴紝鍥犳寰峰浗姹借溅澶氶噰鐢ㄥ痉鍥藉垎绾ф硶锛氭牴鎹痉鍥芥苯杞﹀垎绾ф爣鍑嗭紝A0銆丄00绾...
  • 濂崇敓鍙戜釜c鏄粈涔堟剰鎬濆晩
    绛旓細濂崇敓鍙戜釜c鏄粈涔堟剰鎬濆晩 闅忕潃鏃朵唬鐨勫彂灞,濂虫ф濇兂鍙戠敓浜嗙炕澶╄鍦扮殑鍙樺寲,杩囧幓濂抽潬鐢,鐜板湪濂虫у垯宕囧皻鐙珛,浠ヤ笅鎴戜负澶у鍒嗕韩濂崇敓鍙戜釜c鏄粈涔堟剰鎬濆晩锛屽揩鏉ョ湅鐪嬪惂 濂崇敓鍙戜釜c鏄粈涔堟剰鎬濆晩1 c鐨勬剰鎬濇槸 濞 灏辨槸璇翠汉 榛橀粯鍞у敡 涓嶅お鐖蜂滑 褰㈠璇嶏紝c鍗砪issy锛岃宑issy=sissy锛宻issy鎰忎负鏌斿急鎴栨急鐨勭敺瀛┿...
  • 扩展阅读:c# async ... c#教程官网 ... c#关闭thread线程 ... 电子琴指法图 口诀 ... c#菜鸟教程 ... c#编写简单的计算器 使 ... c#入门视频教程 免费 ... c# sunnyui ... c#缺少程序集引用 ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网