Re: Embedding Visio in .net based Windows Forms Application
- From: "Michel LAPLANE" <mich.laplane@xxxxxxxxxx>
- Date: Fri, 29 Sep 2006 19:26:36 +0200
Hi,
Change to this
VisStencil = VisApp.Documents.Add("Basic shapes.vss");
VisMaster = VisStencil.Masters.Add();
VisMaster.Name = "Rectangle";
VisMaster = VisStencil.Masters[("Rectangle")];
VisShape = VisApp.ActivePage.Drop(VisMaster, 4, 4);
VisShape.Text = "HELLO WORLD";
You know document is a collection so you must use Add.
Stencil have also a collection of masters so use add.
For retrieving a master you must get it out of the master collection.
"Naga" <nagar@xxxxxxxxxxx> a écrit dans le message de news:
1159042158.630546.123800@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello,
I am using Visual studio.net to programmitically control Visio 2003.
I read some of the MSDN articles about this topic and trying to develop
some small sample programs.
I got some sample program devloped in VB 6.0 that just opens Visio
document with basic diagrams template with Basic shapes and then adds
Rectangle shape to the drawing and then sets the text to "HELLO WORLD".
so The VB code to achecive this task is as follows.
Sub HelloWorld ()
'Instance of Visio
Dim appVisio As Visio.Application
'Documents collection of instance
Dim docsObj As Visio.Documents
'Document to work in
Dim docObj As Visio.Document
'Stencil that contains master
Dim stnObj As Visio.Document
'Master to drop
Dim mastObj As Visio.Master
'Pages collection of document
Dim pagsObj As Visio.Pages
'Page to work in
Dim pagObj As Visio.Page
'Instance of master on page
Dim shpObj As Visio.Shape
'Create an instance of Visio and create a document based on the
'Basic Diagram template. It doesn't matter if an instance of
'Visio is already running;the program will run a new one.
Set appVisio = CreateObject("visio.application")
Set docsObj = appVisio.Documents
'Create a document based on the Basic Diagram template that
'automatically opens the Basic Shapes stencil.
Set docObj = docsObj.Add("Basic Diagram.vst")
Set pagsObj = appVisio.ActiveDocument.Pages
'A new document always has at least one page, whose index in the
'Pages collection is 1.
Set pagObj = pagsObj.Item(1)
Set stnObj = appVisio.Documents("Basic Shapes.vss")
Set mastObj = stnObj.Masters("Rectangle")
'Drop the rectangle in the approximate middle of the page.
'Coordinates passed with the Drop method are always inches.
Set shpObj = pagObj.Drop(mastObj, 4.25, 5.5)
'Set the text of the rectangle
shpObj.Text = "Hello World!"
'Save the drawing and quit Visio. The message pauses the program
'so you can see the Visio drawing before the instance closes.
docObj.SaveAs "hello.vsd"
MsgBox "Drawing finished!", , "Hello World!"
appVisio.Quit
End Sub
So I used the above code to generate #C.net code as shown below by
adding VISIO ActiveX control to my Windows Form.
private Visio.Application VisApp = null;
private Visio.Page VisPage = null; private
Visio.Document VisDocument = null;
private Visio.Documents VisDocuments = null;
private Visio.Window VisWindow = null;
private Visio.Document VisStencil = null;
private Visio.Pages VisPages = null;
private Visio.Master VisMaster = null;
private Visio.Shape VisShape = null;
VisApp = (Visio.Application)axDrawingControl1.Window.Application;
VisPage = (Visio.Page) axDrawingControl1.Document.Pages[1];
VisWindow = (Visio.Window) axDrawingControl1.Window;
VisDocument = (Visio.Document) axDrawingControl1.Document;
VisDocuments =
(Visio.Documents)
axDrawingControl1.Window.Application.Documents;
VisDocument = VisDocuments.Add("Basic Diagram.vst");
VisPages = (Visio.Pages)axDrawingControl1.Document.Pages;
VisStencil = VisApp.Documents("Basic shapes.vss");
VisMaster = VisStencil.Masters("Rectangle");
VisShape = VisPage.Drop(VisMaster,4.25,5.5);
VisShape.Text = "HELLO WORLD";
If I execute the above #C code I am getting a compile errors for the
following two statements
VisStencil = VisApp.Documents("Basic shapes.vss");
VisMaster = VisStencil.Masters("Rectangle");
Does anybody know How to fix this problem? I will appreciate your help.
Thanks,
Naga.
.
- Prev by Date: Re: Visio Walls and Dimensioning Help Request
- Next by Date: Re: Setting magnication option for entire document
- Previous by thread: Re: Visio Walls and Dimensioning Help Request
- Next by thread: Re: Problem with IF statement
- Index(es):
Relevant Pages
|