Nevron .NET Vision
Diagram for .NET / Getting Started / Integrating ThinWeb Diagram / View
In This Topic
    View
    In This Topic

    The ThinWeb Diagram has a View object exposed form the View property of the control. This object controls how the diagram is positioned inside the box defined by the control.

    WindowOrigin

    The WindowOrigin defines a point that is mapped to the top left corner of the control view box. The following code snippet modifies the window origin:

     

    C#
    Copy Code

    NThinDiagramControl1.View.WindowOrigin = new NPointF(100, 100);

    Visual Basic
    Copy Code

    NThinDiagramControl1.View.WindowOrigin = New NPointF(100, 100)

    Layout

    The positioning of the document relative to the control box is controlled trough the Layout property of the View. The following table lists the available options:

    Layout Description
    Normal The document is displayed with the control box with uniform scaling. This is the default.
    Fit The document is fit inside the control box (preserves the aspect ratio).
    Stretch The document is stretched to the control box (breaks the aspect ratio)
    StretchToWidth The document is stretched to the control box width (preserves the aspect ratio)
    StretchToHeight The document is stretched to the control box height (preserves the aspect ratio)

    The following code modifies the view layout to Fit:

    C#
    Copy Code

    NThinDiagramControl1.View.Layout = CanvasLayout.Fit;

    Visual Basic
    Copy Code

    NThinDiagramControl1.View.Layout = CanvasLayout.Fit

    Zooming

    The document ZoomingFactor allows you to specify the scaling of the document. A value of 1 means no scaling - the following code specifies that the document should be displayed two times larger than its original size:

    C#
    Copy Code

    NThinDiagramControl1.View.ZoomFactor = 2;

    Visual Basic
    Copy Code

    NThinDiagramControl1.View.ZoomFactor = 2

    When you give the user the the ability to zoom in or out trough the rect zoom tool or the zoom in / out actions on the toolbar it's sometimes useful to be able to restrict the user from specifying a very small or large zoom factor. This is achieved trough the MinZoomFactor and MaxZoomFactor properties, which by default are set to 0.1 and 10. This means that by default the user is allowed to zoom in/out 10 times the original document size. The following code snippet shows how to restrict the user from zooming out the diagram less its original size:

    C#
    Copy Code

    NThinDiagramControl1.View.MinZoomFactor = 1;
    NThinDiagramControl1.View.MaxZoomFactor = 10;

    Visual Basic
    Copy Code

    NThinDiagramControl1.View.MinZoomFactor = 1
    NThinDiagramControl1.View.MaxZoomFactor = 10

    The zoom in / out actions on the toolbar use the value of ZoomFactor and ZoomPercent properties to compute the new ZoomFactor using the following formulas:

    ZoomIn

    ZoomFactor = ZoomFactor * 100 / ZoomPercent;

    ZoomOut

    ZoomFactor = ZoomFactor * ZoomPercent / 100.0f;

    The default value of this property is 90 meaning a zoom out produces an image 10% smaller than the original and a zoom in and a zoom in produces an image 10% larger. The following code snippet changes the zoom percent to 50 - then each zoom in / out action will result in a diagram image twice larger or smaller respectively: 

    C#
    Copy Code

    NThinDiagramControl1.View.ZoomPercent = 50;

    Visual Basic
    Copy Code

    NThinDiagramControl1.View.ZoomPercent = 50