Visio OCX

  • Thread starter Jens Stjärna
  • Start date
J

Jens Stjärna

HI.
I have a question regarding the Visio OCX.
My Project:
I'm going to write a C# windows app in VS2003. The Main form shall contain a
Visio OCX and some standard windows controls. Using the Form UI i want to
drop and connect prefabricated objects from a stencil programmatically.
Should not be so difficult one would think, but i'v spent hours and hours in
the Visio object model pondering this.
I'v read that the OCX can only contain one document at the time. Does this
mean that i cannot have my target Page open and a stencil at the same time?
Must i switch between documents to do this?
In addition to what I mentioned above the app should also perform basic
tasks as open, close, save, saveas, delete documents.
Is there any nice code examples similar to this?

help appreciated.
Thanks, Jens
 
R

Roger

Hello Jens
You can have a document and several Visio stencils all open in a single
instance of the Visio OCX or Drawing Control. Users can drag and drop masters
from the stencils in the normal Visio manner and your program can do the same.

Opening, closing, saving and deleting Visio documents can all be done under
program control. The Visio 2003 SDK, which is free to download from the
Microsoft web site, contains some useful code examples in C# and VB. Also I'd
recommend you obtain a copy of Graham Wideman's excellent "Visio 2003
Developer's Survival Pack" book.

Best regards
Roger Billsdon
 
J

Jens Stjärna

Thanks, Roger.
I'v now ordered the book from Amazon.
In the mean time, I do have the SDK but it does not focus on OCX usage.
Since the OCX can hold only one Document, it does not have a Documents
collection? How can i Load, store and use several documents (stencils are
documents too, arnt' they?) , or is it maby so, that it cannot display
multiple documents, but it can hold them, and one would need to switch
inbetween to retrive a master from a stencil document and place it on a
normal Visio drawing?

Is there any other code out there with c# and Visio OCX?
Thanks, Jens
 
R

Roger

Hi Jens

Included in the SDK is a sample named "Office Plan". This is a C# program
which uses the Visio drawing control and includes code for dropping masters
from a Visio stencil named "Sample Office Furniture.vss" which is also
included in the SDK.

Although the Visio Drawing Control is limited to a single document for
editing, stencils can be opened and displayed along with the document. The
Visio application object includes a document collection property which, via
the usual .add and .item properties enables access to stencils. For example,
in VB 2005 to iterate through all the stencils open in the Visio Drawing
Control:

Docs = VDC.Document.Application.Documents
iDocs = Docs.Count
For iDoc = 1 to iDocs
oDoc = Docs.Item(iDoc)
If oDoc.Type = Visio.VisDocumentTypes.visTypeStencil Then
'-- Process
End If
Next iDoc

Best regards
Roger Billsdon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top