2013-07-19 21 views
2

好吧,我一直試圖在一個形狀中創建一個新的自定義屬性,然後我以某種方式管理,但是,當我嘗試更改標籤的名稱時,我只能寫入數字。你能否告訴我如何在C#或VB中做到這一點,我可以得到一個提示?如何在Visio C#中編寫Shape的屬性?

我的代碼是:

//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 

然而,當結果方法只接受布爾作爲輸入,我不知道如何寫一個字符串overthere ...提前

謝謝!

回答

2

我也一直在研究如何設置自定義形狀數據屬性的字符串值。 剛剛纔到這樣的工作:

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

聲明,我使用Visio自動化方面的專家,但在我的情況下工作。 我正在使用visio 2010和studio 2010 希望它有幫助。

0

結果並不意味着讀/寫。你想要做的是將單元格的FormulaU屬性設置爲標籤名稱。 Result屬性只計​​算單元格的公式並返回結果,這就是爲什麼您必須爲返回值提供單位。

此外,AddRow方法返回添加行的實際行號,該行不一定是您指定的行。對於具有可命名行的形狀表格部分,如自定義屬性部分,Visio可能會忽略您請求的行並將其粘貼在底部。

1

您可以使用下面的代碼:

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); 
      } 

     } 
相關問題