[CLSCompliant(false)]
public static bool HasShapeInWindow(Window window)
{
bool result = false;
try
{
window.SelectAll();
result = (window.Selection.Count > 0);
window.DeselectAll();
}
catch { }
return result;
}
Visio.Page page = VisioUtility.GetPage(VisDocument, "饋線圖");
if (page.Shapes.Count <= 0)
{
MessageUtil.ShowTips("圖紙上沒有設備");
return;
}
[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;
}
| 維度 | SelectAll 法 | Shapes.Count 法 |
|---|---|---|
| 速度 | 較慢 (選取操作) | 較快 (直接屬性) |
| 事件干擾 | 觸發 SelectionChanged | 無副作用 |
| 適用場景 | 需同步選取狀態時 | 純判斷、事件處理中 |
若訂閱 SelectionChanged 事件 (如 ctrlDrawing_SelectionChanged),禁止使用方法一,否則會觸發遞迴事件導致邏輯錯誤或效能問題。此時必須使用方法二。