如何在Visio中设置形状,字体和前景色

时间:2014-02-12 05:03:54

标签: c# visio

我需要在我的Visio文件中添加一个矩形,并想要设置字体和文本颜色, 我怎样才能做到这一点?

visio.Application app = new visio.Application();
visio.Document doc;
doc = app.Documents.Open(processPath);

visio.Page page = doc.Pages[1];
CreateVisio vis = new CreateVisio();
visio.Shape edit = page.DrawRectangle(3.2d, 6.9d, 4.9d, 7.9d);

2 个答案:

答案 0 :(得分:2)

如何创建新的VISIO文档

Microsoft.Office.Interop.Visio.Application application = 
        new Microsoft.Office.Interop.Visio.Application();  
application.Visible = false; 
Microsoft.Office.Interop.Visio.Document doc = application.Documents.Add(templatePath);
Microsoft.Office.Interop.Visio.Page page = application.Documents[1].Pages[1];

如何获取正在处理的工作表的宽度和高度

double xPosition = page.PageSheet.get_CellsU("PageWidth").ResultIU;
double yPosition = page.PageSheet.get_CellsU("PageHeight").ResultIU; 

我们正在使用有关纸张宽度和高度的信息来了解放置方框的位置。我们通过将纸张宽度除以根数来将根盒放在纸张的中间。此外,我们从yPosition中减去级别编号,以便级别编号增加的框在图表上获得较低的位置。

如何创建形状并将其放在图表上(删除它)

//creating the type of shape in the organizational chart it could be: "Position", 
//"Executive", "Manager",  "Assistant" and others according 
//to what you have in your stencil. 
Microsoft.Office.Interop.Visio.Master position = doc.Masters.get_ItemU("Position"); 
//placing the shape in the xPosition and yPosition coordinates
Microsoft.Office.Interop.Visio.Shape shape = page.Drop(position, xPosition, yPosition);  

如何设置形状属性

//set the text
shape.Text = box.Name;

//set hyperlink
if (!String.IsNullOrEmpty(box.HyperLink.Trim()))
{
     Hyperlink link = shape.Hyperlinks.Add();
     link.Address = box.HyperLink;
}

//set the shape width
shape.get_CellsSRC(
                (short)Microsoft.Office.Interop.Visio.VisSectionIndices.
                visSectionObject,
                (short)Microsoft.Office.Interop.Visio.VisRowIndices.
                visRowXFormIn,
                (short)Microsoft.Office.Interop.Visio.VisCellIndices.
                visXFormWidth).ResultIU = box.Width;

//set the shape height
shape.get_CellsSRC(
               (short)Microsoft.Office.Interop.Visio.VisSectionIndices.
               visSectionObject,
               (short)Microsoft.Office.Interop.Visio.VisRowIndices.
               visRowXFormIn,
               (short)Microsoft.Office.Interop.Visio.VisCellIndices.
               visXFormHeight).ResultIU = box.Height;

//set the shape fore color
shape.Characters.set_CharProps(
                (short)Microsoft.Office.Interop.Visio.
                    VisCellIndices.visCharacterColor,
                (short)Utilities.GetVisioColor(box.ForeColor));

//set the shape back color
shape.get_CellsSRC((short)VisSectionIndices.visSectionObject,
         (short)VisRowIndices.visRowFill, 
    (short)VisCellIndices.visFillForegnd).FormulaU = 
    "RGB(" + box.BackColor.R.ToString() + "," + box.BackColor.G.ToString() + "," 
    + box.BackColor.B.ToString() + ")"; 

使用connectWithDynamicGlueAndConnector()方法连接形状。此方法接受两个参数,父形状和childShape,并将在它们之间创建连接器。这种方法与VISIO SDK中的方法完全相同。

答案 1 :(得分:0)