正如我在上面的答案中提到的(您已将其标记为无用),您的目标是错误的形状。
既然您已经编辑了您的问题以包含更多详细信息,那么您正在处理的形状很清楚。
您定位的形状似乎是“BPMN 基本形状”模具中的“折叠子流程”。这是一个组形状,顶层没有几何形状,所以改变它的颜色,就像你在你的问题中所做的那样,没有视觉上的变化。要解决这个问题,您需要找到用于显示背景的子形状。碰巧在这个特定的母版中,包含您需要定位的填充的子形状的索引比父形状大一,因此您可以在代码中使用它。该形状缺少任何其他清晰的特征(例如用户单元格),这些特征会成为更好的候选者,因此请注意,此方法仅适用于该特定形状。
鉴于您似乎正在使用此模板进行大量工作,我的方法是创建模板的副本并对母版进行一些修改以使这种交互更容易一些,但我希望同时以下代码回答了您的问题。
如果是这样,请将其标记为已回答。
public void OnCheckFillBPMN()
{
Color fillColor = Color.FromArgb(1, 255, 0, 0);
CollapsedSubProcessFill(this.Application.ActiveWindow.Selection.PrimaryItem, fillColor);
}
private void CollapsedSubProcessFill(Visio.Shape vShpIn, Color fillColor)
{
if (vShpIn != null && vShpIn.Master != null && vShpIn.Master.NameU.StartsWith("Collapsed Sub-Process"))
{
//The sub-shape that provides the fill colour in
//the 'Collapsed Sub-Process' master is the first index
//after the group shape.
//If you want to use a different method to locate the
//correct sub-shape then do that here.
var targetSubShpId = vShpIn.ID + 1;
var targetShp = TryGetShapeInCollection(vShpIn.Shapes, targetSubShpId);
if (targetShp != null)
{
var targetCell = targetShp.get_CellsSRC(
(short)Visio.VisSectionIndices.visSectionObject,
(short)Visio.VisRowIndices.visRowFill,
(short)Visio.VisCellIndices.visFillForegnd);
targetCell.FormulaU = "RGB(" + fillColor.R
+ ',' + fillColor.G
+ ',' + fillColor.B + ')';
}
}
}
private Visio.Shape TryGetShapeInCollection(Visio.Shapes vShps, int shpId)
{
try
{
if (vShps != null)
{
var targetShp = vShps.ItemFromID[shpId];
return targetShp;
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
if (ex.ErrorCode == -2032465756) //Invalid sheet identifier
{
return null;
}
}
return null;
}