/// <summary>
/// 判断是否有对象选定
/// </summary>
/// <param name="window"></param>
/// <returns></returns>
[CLSCompliant(false)]
public static bool HasShapeInWindow(Window window)
{
bool result = false;
try
{
window.SelectAll();
result = (window.Selection.Count > 0);
window.DeselectAll();
}
catch
{ ;}
return result;
}
/// 判断是否有对象选定
/// </summary>
/// <param name="window"></param>
/// <returns></returns>
[CLSCompliant(false)]
public static bool HasShapeInWindow(Window window)
{
bool result = false;
try
{
window.SelectAll();
result = (window.Selection.Count > 0);
window.DeselectAll();
}
catch
{ ;}
return result;
}
另外一种方法是判断页面对象Page的Shapes对象集合是否大于0即可,如下:
Visio.Page page = VisioUtility.GetPage(VisDocument, "馈线图");
if (page.Shapes.Count <= 0)
{
MessageUtil.ShowTips("图纸上没有设备");
return;
}
if (page.Shapes.Count <= 0)
{
MessageUtil.ShowTips("图纸上没有设备");
return;
}
/// <summary>
/// 获取Visio文档制定的页面对象
/// </summary>
/// <param name="visDocument"></param>
/// <param name="pageType"></param>
/// <returns></returns>
[CLSCompliant(false)]
public static Page GetPage(Document visDocument, string pageType)
{
Page visPage;
for (int i = 1; i <= visDocument.Pages.Count; i++)
{
visPage = visDocument.Pages[i];
if (FormulaStringToString(visPage.PageSheet.get_Cells(CUST_PROP_PREFIX + "绘图页").Formula) == pageType)
{
return visPage;
}
}
return null;
}
/// 获取Visio文档制定的页面对象
/// </summary>
/// <param name="visDocument"></param>
/// <param name="pageType"></param>
/// <returns></returns>
[CLSCompliant(false)]
public static Page GetPage(Document visDocument, string pageType)
{
Page visPage;
for (int i = 1; i <= visDocument.Pages.Count; i++)
{
visPage = visDocument.Pages[i];
if (FormulaStringToString(visPage.PageSheet.get_Cells(CUST_PROP_PREFIX + "绘图页").Formula) == pageType)
{
return visPage;
}
}
return null;
}
两种方法基本上效果一样, 第二种方法可能速度会快一些,如果你在Visio的Document对象事件中有处理逻辑的时候, 如下所示, 而且有的情况下,你还不能用第一种方式来进行判断:
this.CtrlDrawing.SelectionChanged += new EVisOcx_SelectionChangedEventHandler(ctrlDrawing_SelectionChanged);
希望你能发现更多好玩的东西,呵呵
转载请注明出处:
撰写人:伍华聪 http://www.iqidi.com
撰写人:伍华聪 http://www.iqidi.com