如何书写形状';s在Visio C#中的属性

本文关键字:Visio 属性 何书写 书写 | 更新日期: 2023-09-27 18:24:06

好吧,我一直在尝试在形状中创建一个新的自定义属性,但不知怎么的,当我尝试更改标签的名称时,我只能写数字。你能给我提供如何在C#或VB中做到这一点吗?这样我就可以得到提示了?

我的代码是:

//First I create the row
shape.AddRow((short)VisSectionIndices.visSectionProp,(short) (iRow + 1), (short) VisRowTags.visTagDefault);
//And now I try to write the Label
shape.CellsSRC[(short)VisSectionIndices.visSectionProp, (short)(iRow + 1), (short)VisCellIndices.visCustPropsLabel].Result[VisUnitCodes.visNoCast] = 123456789

然而,当Result方法只接受布尔值作为输入,而我不知道如何在上面写一个字符串。。。

提前感谢!

如何书写形状';s在Visio C#中的属性

我也一直在研究如何设置自定义形状数据属性的字符串值。只是让它像这样工作:

var newPropertyValue = "cool new value";
tstShape.Cells["Prop.SuperCustomPropertyName"].FormulaU = "'"" + newPropertyValue + "'"";

免责声明:我不是Visio Automation的专家,但它适用于我的情况。我正在使用visio 2010和studio 2010希望它能有所帮助。

您可以使用以下代码:

private void AddCustomProperty(Microsoft.Office.Interop.Visio.Shape shape, string PropertyName, String propertyValue)
        {
            try
            {
                short customProps = (short)VisSectionIndices.visSectionProp;      
                short rowNumber = shape.AddRow(customProps, (short)VisRowIndices.visRowLast, (short)VisRowTags.visTagDefault);
                shape.CellsSRC[customProps, rowNumber, (short)VisCellIndices.visCustPropsLabel].FormulaU = "'"" + PropertyName + "'"";
                shape.CellsSRC[customProps, rowNumber, (short)VisCellIndices.visCustPropsValue].FormulaU = "'"" + propertyValue + "'"";

            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + e.Message);
            }
        }

结果不是读/写的。您要做的是将单元格的FormulaU属性设置为标签名称。Result属性只计算单元格的公式并返回结果,这就是为什么必须为返回值提供单位的原因。

此外,AddRow方法返回添加的行的实际行号,该行不一定是您指定的行。对于具有可命名行的形状表部分,如"自定义属性"部分,Visio可能会忽略您请求的行,并将其粘贴在底部。