.NET Tips and Tricks

Blog archive

Nevron Diagram for .NET: Drawing and Loading a Diagram

I was being dumb about drawing a diagram for Nevron's Diagram for .NET. I went back to my Start menu and looked under Nevron .NET Vision 2010.1 for VS2008 | Nevron Diagram | WinForm. There I found (eureka!) Nevron's Diagram Designer. I opened it and found what looks like a very complete object drawing tool. I used it to create a simple diagram (see Figure 1)


[Click on image for larger view.]
Figure 1. Nevron's Diagram for .NET package includes the Diagram Designer, which allows you to create a diagram without code.

Now that I've created a diagram, I want to load it into my form for the user to interact with it. It took a little while to recognize that Nevron makes a distinction between "persistent documents" (documents saved to your hard disk) and "drawing documents" (documents in memory). My saved diagram is a persistent document that I need to convert to a drawing document. The tool to do that, it turns out, is the PersistencyManager. I also had to recognize that I wanted to load the resulting drawing document into the NDiagramView control on my form (I had assumed that I would be putting it in the NDiagramDocument).

A search for "diagram designer" on the Nevron site put it all together for me and gave me these four lines of code to display my diagram (see Figure 2):

Dim pm As New NPersistencyManager
Dim ddoc As NDrawingDocument
ddoc = pm.LoadDrawingFromFile( _
"C:\Course\512\PHVSampleDiagram.ndb")
Me.NDrawingView1.Document = ddoc

[Click on image for larger view.]
Figure 2. Working with Nevron's PersistencyManager object you can load diagrams created with the Nevron Diagram Designer into a window on your form.

What's cool about the diagram now displayed in my Visual Basic form is that the user can interact with it. If I don't lock the diagram, for instance, the user can drag the shapes around, double click the shapes to enter text into them -- basically, do all the things that you'd expect the user to do with a drawing tool (one suspects that Nevron's Diagram Designer is simply built with the same components that I'm using here). If I added more of the Diagram for .NET controls to my form I could define my own shapes and let users use them to create controls in my form.

I set some more properties to get the display I wanted. I also (finally) picked up my license key to get rid of the demo notice that my diagrams were displaying. I'm now ready to move onto the next part of my test: Tying code to my user's interaction with the diagram.

Posted by Peter Vogel on 05/16/2010


comments powered by Disqus

Featured

Subscribe on YouTube