我想通过代码更改Visio中BPMN-Shape的颜色。到目前为止我所做的是使用以下代码片段更改Visio中ShapeSheet的“LineColor”单元格的值:
_startShape.CellsU["LineColor"].FormulaForceU = "=RGB(255,0,0)";
但是,我自己绘制的形状并没有改变颜色。 ShapeSheet-Cell中的信息/值正在变化,但颜色仍然不可见。我读到了保护细胞的GUARD功能,但是FormulaForceU
应该忽略GUARD。
导入的形状正在按预期变化!只是自绘不会变为红色(RGB(255,0,0)。
我无法弄清楚为什么!有谁经历过同样的经历?
提前致谢!
如果形状是一个组,那么您还需要更改子形状。
尝试使用visio默认系统颜色常量 - vbRed或2 - VisDefaultColors Enumeration (Visio)
_startShape.CellsU [“LineColor”]。FormulaForceU = 2;
我发现这个建议(使用CellsSRC语法)在俄罗斯stackoverflow发布Change text color in Visio
Visio.Cell colorCell = shape.get_CellsSRC((短)Visio.VisSectionIndices.visSectionCharacter,(简称)Visio.VisRowIndices.visRowCharacter,(简称)Visio.VisCellIndices.visCharacterColor); colorCell.FormulaForceU =“RGB(0,255,255)”;
我有适合我的解决方案。我不相信这是最好的,因为Surrogate指出你可以潜入形状解剖,并准确看看你需要改变什么。但是,如果没有这种迭代方法,我仍然无法弄清楚如何精确地获得需要改变的形状。此代码正在更改形状线条颜色而没有副作用。
public static void HighlightShape(Shape shape)
{
if (shape == null) {
return;
}
var processList = new Queue<Shape>();
processList.Enqueue(shape);
var allShapes = new List<Shape>();
allShapes.Add(shape);
while (processList.Count > 0)
{
var s = processList.Dequeue();
allShapes.Add(s);
if (s.Shapes != null) {
foreach (Shape subshape in s.Shapes) {
processList.Enqueue(subshape);
}
}
}
foreach (Shape s in allShapes)
{
s.CellsU["LineColor"].FormulaForceU = "THEMEGUARD(RGB(255,255,0))";
}
}