This project has moved and is read-only. For the latest updates, please go here.

Top-left positioning of diagram

Mar 26, 2014 at 8:39 AM
Hi

Within Display, the diagram is always horizontally centered. Would it be possible to implement the ability to select whether the diagram would positioned top-left or centered?

This is very useful if NShape is used to draw / display / design visual appearance of a screen (as it is in my case).

Thanks,
Zvonko
Mar 27, 2014 at 2:23 PM
You can implement this behavior rather simple:
After setting the diagram to the (visible) display, call display.EnsureVisible(0, 0) to scroll to the top left corner of the diagram.

Other helpful events for customizing the display view:
Display.ZoomChanged
Display.DiagramChanged
Mar 27, 2014 at 2:39 PM
I see. But that only moves the display to the specific diagram coordinate. And when you resize the window or zoom the diagram, the diagram is repositioned within display control.

What I would like to achieve (and also suggest you as a feature) is ability for diagram not to be horizontally and vertically centered on display control but rather have the (0,0) coordinate of diagram be the same as (0,0) coordinate of the display control (top-left alignment of the diagram within display control).

I played around a little with the source, see this picture: http://snag.gy/2B8xl.jpg
Mar 27, 2014 at 2:58 PM
zmanbb wrote:
I see. But that only moves the display to the specific diagram coordinate. And when you resize the window or zoom the diagram, the diagram is repositioned within display control.
That's why I mentioned ZoomChanged. Try this code in the display.ZoomChanged event handler:
private void display_ZoomChanged(object sender, EventArgs e) {
    Display display = ...;
    // Get the diagram area currently visible
    Rectangle viewArea = Rectangle.Empty;
    display.ControlToDiagram(CurrentDisplay.DrawBounds, out viewArea);
    // Move the view area to the top left corner
    viewArea.X = viewArea.Y = 0;
    CurrentDisplay.EnsureVisible(viewArea);
}
zmanbb wrote:
What I would like to achieve (and also suggest you as a feature) is ability for diagram not to be horizontally and vertically centered on display control but rather have the (0,0) coordinate of diagram be the same as (0,0) coordinate of the display control (top-left alignment of the diagram within display control).
I will put your suggestion on our list of points to discuss, but I cannot promise you anything.
Usually, people expect that the contents of the display stay where they are when zooming and they also expect that zooming with mousewheel follows the position of the mouse. So we have to discuss your proposal.
But you can still derive your own display and implement the feature yourself (let me know if you need help).
Mar 27, 2014 at 3:05 PM
Usually, people expect that the contents of the display stay where they are when zooming and they also expect that zooming with mousewheel follows the position of the mouse.
I totally agree with you. That is why this "mode" should be selectable (via property).
And the behaviour should be the same as when zooming in/out the content of Visual Studio text editor.