Diagram for .NET / User's Guide / Document Object Model / Library Documents

In This Topic
    Library Documents
    In This Topic

    Library documents (or simply libraries) are represented by the NLibraryDocument class (derived from NDocument). This type of document is in fact a collection of masters. Masters are reusable drawing clippings, which can be instanced in every drawing. Library documents are components, which appear in the Visual Studio toolbox.  They are represented by the following item:

    In the context of WinForms drawing documents are displayed and edited with the help of a NLibraryView instance(s).

     Masters

    Masters are collections of diagram elements, which can be reused in multiple drawings. Masters are stored in libraries. Masters store all the needed information, which is required for the proper duplication of the elements they contain. Currently this includes:

    • Measurement Unit - the logical measurement unit associated with the elements of the master. Accessible from the MeasurementUnit property.
    • Connection Container - the connections between the elements in the master. Accessible from the ConnectionContainer property.

    In order for masters to be displayed in library views, each master must provide three images:

    • List image - typically a 16x16 bitmap. Used to display the master in list view style.
    • Icon image - typically a 32x32 bitmap. Used to display the master in icons view style.
    • Thumbnail image - typically a 64x64 bitmap. Used to display the master in thumbnails view style.

    If one of these images is not specified (which is the most common case) it will be automatically generated for the master, from an instance of the NMasterImageGenerator class, which is an attribute of every library.

    You can easily create a master from any set of diagram elements. The following example creates a master, which contains a rectangle shape, measured in millimeters:

    C#
    Copy Code
    NRectangleShape rect = new NRectangleShape(0, 0, 30, 30);
    NMaster master = new NMaster(rect, NGraphicsUnit.Millimeter, "My first master", "Drag me on the drawing");
    library.AddChild(master);
    
    Visual Basic
    Copy Code
    Dim rect As New NRectangleShape(0, 0, 30, 30)
    Dim master As New NMaster(rect, NGraphicsUnit.Millimeter, "My first master", "Drag me on the drawing")
    library.AddChild(master)
    
     Data exchange

    By default libraries add an instance of the NLibraryDataObjectAdaptor class to their DataObjectAdaptors collection. This type of adaptor can adapt data objects of the following formats:

    • Text - converts any text as a NTextShape instance wrapped in a NLibraryDataObject instance. This helps you paste and drop text in the libraries.
    • Library data object - converts any NLibraryDataObject instance to NLibraryDataObject instance. This helps you paste and drop masters from one library to another.
    • Drawing data object - converts any NDrawingDataObject  instance to NLibraryDataObject instance. This helps you paste and drop drawing clippings in libraries as masters.
     Related Examples
    Windows Forms: Visual Interface Components - Library Browser
    See Also