Visio開發基礎
Visio SDK 2007
VisSDK.chm
Visio代碼示例庫. chm
Visio文檔操作
查看ShapeSheet屬性和幫助內容。
宏的錄制
Visio的幾個重要對象
應用
窗口(應用程序。活動窗口)
文檔(應用程序。活動文檔)
主人、形狀
Visio XML格式文件的分析
主格式
頁面/形狀格式
在繪圖的XML文檔中,在主控形狀之後的Shapes集合中只有壹個Shape對象。
圖形集有多個對象,每個對象的NameU和Name值可能不同,所以壹般使用NameU。
Visio中基本操作的實現
visa application = this . ctrl drawing . document . application;
VisWindow = VisApplication。活動窗口;
VisDocument = VisApplication。主動文檔;
//設置
visa應用程序。settings . ShowShapeSearchPane = false;//顯示搜索形狀表單
visa應用程序。settings . enable auto connect = false;//自動鏈接(2007默認)
visa應用程序。settings . stencil background color = 10070188;//vbGrayText
//文檔的各種顯示
visa應用程序。DoCmd((short)visuicmds . viscmdviewrulers);
visa應用程序。DoCmd((short)visuicmds . viscmdviewgrid);
visa應用程序。DoCmd((短)VisUICmds。show guides);
visa應用程序。DoCmd((短)VisUICmds。ShowConnectPoints);
visa應用程序。DoCmd((短)VisUICmds。showpage breaks);
//各種窗口
visa應用程序。DoCmd((short)visuicmds . viscmdshapeswindow);
visa應用程序。DoCmd((short)visuicmds . viscmdpanzoom);
visa應用程序。DoCmd((short)visuicmds . viscmdcustprop);
visa應用程序。DoCmd((short)visuicmds . viscmdsizepos);
發送鍵。send("^(x)”);
//visa application。DoCmd((short)visuicmds . viscmdufeditcut);
發送鍵。發送(“{ DELETE }”);
//visa application。DoCmd((short)visuicmds . viscmdufeditclear);
發送鍵。send("^+(p)”);
//visa application。DoCmd(visuicmds . viscmdformatpainter);
發送鍵。send("^(z)”);
//visa application。DoCmd(visuicmds . viscmdeditundo);
調用工具欄對象和菜單對象的方法
申請。命令欄
微軟。Office.core.commandbars * * *很喜歡Office對象模型。
使用CommandBar而不是UIObject。
在CommandBar對象中,菜單和工具欄是壹回事。
CommandBar、CommandBarButton、CommandBarComboBox、CommandBarControl和CommandBarPopup。
示例:執行視圖中工具欄的所有按鈕事件。
微軟。office . core . command bars command bars;
commandBars =(微軟。office . core . command bars)visa application。命令欄;
foreach(微軟。commandBars["View"]中的Office.Core.CommandBarControl控件。控件)
{
微軟。office . core . commandbarbutton button =控件as Microsoft。Office . Core.CommandBarButton
如果(按鈕!=空)
{
按鈕。執行();
}
}
StringBuilder sb = new StringBuilder();
foreach(微軟。命令欄中的Office.Core.CommandBar欄)
{
某人(somebody的簡寫)追加(字符串。Format("CommandBar Name:{0}\r\n ",Bar。姓名));
foreach(微軟。bar中的Office.Core.CommandBarControl控件。控件)
{
微軟。office . core . commandbarbutton button =控件as Microsoft。Office . Core.CommandBarButton
如果(按鈕!=空)
{
某人(somebody的簡寫)追加(字符串。Format("按鈕名稱:{0} \r\n ",按鈕。caption));
}
}
}
form 2 frm = new form 2();
frm.txtContent.Text = sb。ToString();
frm。show();
short flags =(short)visopensaveargs . visopendocked |(short)visopensaveargs . visopenro;
StencilOpenEx(wndVisio。應用程序、標誌);
/**////<概要>
///男* *開模方法
///
//< param name = "visa PP " >通過引用調用的VisioApplication對象
//< param name = "flags " >打開模式
私有void StencilOpenEx(應用程序visApp,短標誌)
{
list < string > stencil list = get stencils();
字符串stencilFileName
foreach(stencil list中的字符串模具)
{
stencil filename = GetStencilsFileName(stencil);
如果(!字符串。IsNullOrEmpty(stencilFileName))
{
維薩普。documents . OpenEx(portal . GC . gstencilefilebasepath+stencil filename,flags);
}
}
}
//關閉模具文件
維薩普。文檔["Switch.vss"]。close();
維薩普。文檔["Span.vss"]。close();
維薩普。文檔["Line.vss"]。close();
維薩普。文檔["Label.vss"]。close();
維薩普。文檔["Construct.vss"]。close();
維薩普。文檔["Monitor.vss"]。close();
Visio形狀的屬性操作
StringToFormulaForString,公式字符串函數
訪問屬性
設置屬性
添加屬性
//列出模具組
this . cmbstencilgroup . items . clear();
list < string > stencil group = stencil。get stencils();
foreach(stencil groups中的字符串組)
{
this . cmbstencilgroup . items . add(group);
}
//根據模具組列出模具。
string stencilName = stencil。GetStencilsFileName(this . cmbstencilgroup . text);
this . cmbstencil . items . clear();
字符串tempName
foreach(visApp中的Master master。文檔[模板名稱]。大師)
{
tempName = master。姓名;
如果(!模板。IsExcludeItem(tempName))
{
this . cmbstencil . items . add(tempName);
}
}
//根據模具,獲取對應的屬性集,遍歷屬性集,列出屬性名。
string stencilName = stencil。GetStencilsFileName(this . cmbstencilgroup . text);
string master name = this . cmbstencil . text;
Visio。Shape shape = visApp。文檔[模板名稱]。大師[大師名]。形狀[1];
如果(形狀!=空)
{
list < StencilPropertyInfo > prop infos = property。GetPropertyCollection(shape);
foreach(propInfos中的StencilPropertyInfo信息)
{
this . CMB property . items . add(info。姓名);
}
}
//根據模具和模具屬性列出相應的屬性信息。
string stencilName = stencil。GetStencilsFileName(this . cmbstencilgroup . text);
string master name = this . cmbstencil . text;
Visio。Shape shape = visApp。文檔[模板名稱]。大師[大師名]。形狀[1];
StencilPropertyInfo info =屬性。GetProperty(shape,this . CMB property . text);
如果(信息!=空)
{
this.txtName.Text = info。姓名;//屬性名稱
this.txtValue.Text = info。價值;//屬性值
this.txtFormat.Text = info。格式;//屬性格式
this.txtSortKey.Text = info。排序;//屬性的排序
this.txtPrompt.Text = info。提示;//屬性的提示信息
}
//根據模具,得到屬性對象的集合。
公共列表< StencilPropertyInfo > GetPropertyCollection(Visio。形狀形狀)
{
List < StencilPropertyInfo > List = new List < StencilPropertyInfo >();
StencilPropertyInfo property info;
Visio。細胞形狀細胞;
short short section prop =(short)vissectionindexes . vissectionprop;
如果(形狀!=空)
{
for(短I = 0;I < shape . get _ RowCount(short section prop)-1;i++)
{
if(shape . get _ CellsSRCExists(short section prop,I,(short)viscellindexes . viscustpropslabel,0)!= 0)
{
property info = new StencilPropertyInfo();
shape cell = shape . get _ cells src(shortSectionProp,I,(short)viscellindexes . viscustpropslabel);
propertyInfoName = VisioUtility。FormulaStringToString(shape cell。RowNameU);
shape cell = shape . get _ cells src(shortSectionProp,I,(short)viscellindexes . viscustpropsprompt);
propertyInfo提示=可見性。FormulaStringToString(shape cell。FormulaU);
shape cell = shape . get _ cells src(shortSectionProp,I,(short)viscellindexes . viscustpropsformat);
propertyInfo格式=可視性。FormulaStringToString(shape cell。FormulaU);
shape cell = shape . get _ cells src(short section prop,I,(short)viscellindexes . viscustpropsvalue);
propertyInfo價值=可見性。FormulaStringToString(shape cell。FormulaU);
shape cell = shape . get _ cells src(shortSectionProp,I,(short)viscellindexes . viscustpropssortkey);
propertyInfo排序=可見性。FormulaStringToString(shape cell。FormulaU);
//shape cell = shape . get _ cells src(short section prop,I,(short)viscellindexes . viscustpropstype);
//propertyInfo。PropType = VisioUtility。FormulaStringToString(shape cell。FormulaU);
//shape cell = shape . get _ cells src(short section prop,I,(short)viscellindexes . viscustpropsinvis);
//propertyInfo。無形=可見性。FormulaStringToString(shape cell。FormulaU);
// ..
列表。add(property info);
}
}
}
退貨單;
}
//根據模具和屬性名稱,獲取屬性對象信息。
public StencilPropertyInfo GetProperty(Visio。形狀形狀,字符串屬性名稱)
{
list < StencilPropertyInfo > list = GetPropertyCollection(shape);
StencilPropertyInfo property info = null;
foreach(列表中的StencilPropertyInfo tempInfo)
{
if (tempInfo。Name == propertyName)
{
propertyInfo = tempInfo
打破;
}
}
返回propertyInfo
}
=====
我也沒寫過visio操作。這是收集的代碼,對妳沒有幫助hoho。妳可以在CSDN發帖求助。