Microsoft Office Tutorials and References
In Depth Information
Adding shapes to a document at runtime
Let's take a look at the example that Zack created:
Open Visual Studio 2008 to create a new Visio solution, as described earlier.
In the ThisAddIn.cs file, write the following program, to create a Visio
document dynamically:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// Instance for Document object and calling the Add method on
the Document collection
Visio.Document PacktVisioDocument = this.Application.
Documents.Add("");
// Instance of Shape object
// Page Object has a PageSheet to set other page properties
Visio.Shape PacktShape = PacktVisioDocument.Pages[1].PageSheet;
// Set the page width property
PacktShape.get_Cells("PageWidth").Formula = "5.5 in";
// Set the page height property
PacktShape.get_Cells("PageHeight").Formula = "2.5 in";
// Code to add Shape to the document
// Access the Shapes file through Document object
Visio.Document PacktDocStencil = Application.Documents.
OpenEx("BASIC_M.VSS", (short)Visio.VisOpenSaveArgs.
visOpenDocked);
// Drop the new Square Shape to our Visio document
Visio.Shape PacktShape2 = PacktShape.Drop(PacktDocStencil.
Masters["Square"], 10, 7.50);
// Adding text to inside the Shape
PacktShape2.Text = "Packt Shape One";
}
 
Search JabSto ::




Custom Search