透過 ShapeSheet 發現 GroupSelectMode 屬性控制群組選取行為:
[CLSCompliant(false)]
public static void SetGroupSelectMode(Visio.Shape targetShape, int selectMode)
{
targetShape.get_CellsSRC(
(short)VisSectionIndices.visSectionObject,
(short)VisRowIndices.visRowGroup,
(short)VisCellIndices.visGroupSelectMode
).FormulaU = selectMode.ToString();
}
需求:油路分析時,換向閥(群組形狀)需實現子形狀「閥A」右移、「閥B」左移的動態效果。
else if (equipType == "4/2閥")
{
VisioUtility.SetGroupSelectMode(shape, 2); // 切換至子形狀選取模式
foreach (Shape subShape in shape.Shapes)
{
string subEquipType = VisioUtility.GetShapeCellValue(subShape, "設備類型");
if (subEquipType == "閥A" || subEquipType == "閥B")
{
subShape.Text = subEquipType;
if (intValue != 0) continue;
try
{
VisWindow.DeselectAll();
VisWindow.Select(subShape, (short)VisSelectArgs.visSubSelect);
if (subEquipType == "閥A")
VisWindow.Selection.Move(0.393701, 0, "inches"); // 右移
else if (subEquipType == "閥B")
VisWindow.Selection.Move(-0.393701, 0, "inches"); // 左移
Application.DoEvents();
Thread.Sleep(50); // 動畫延遲
}
catch (Exception ex)
{
VisWindow.DeselectAll();
}
}
}
VisioUtility.SetGroupSelectMode(shape, 0); // 還原群組模式
}
visGroupSelectMode 動態切換選取層級Application.DoEvents() + Thread.Sleep() 實現 UI 即時刷新動畫世界本簡單,只因道未知;無師可自通,碼界無秘密。