Send email to GoDiagram at our domain and I'll reply with a very small sample program that displays a couple of GoIconicNodes with a link between them, shows a line grid in the background, and handles a double click in the background to center the diagram using the code from the start of this conversation.
The sample seems to work fine for me and I see no loss in image quality when the diagram is centered. I'd be interested to see if this simple sample works correctly for you. Assuming that it does, we'll need to figure out what additional things in your project might be causing the problem.
First, if I understand you correctly, I think you're trying to scroll the GoView so that a given position within the GoDocument is at the top left of the GoView. To do this you want to be setting the GoView DocPosition property.
The next issue is that the GoView LimitDocPosition method is going to try to limit the value you set for DocPosition so that it is a postion within the current document. In your case I think you'll be scrolling the document horizontally to the right so that the x position of the left side of the GoView will actually be a negative value, and to do that you'd need to extend the document. So it's likely nothing would happen when you changed the DocPosition. To fix this you can change the GoViewSheetStyle so that it isn't None. Then LimitDocPosition won't set any limits on the value of DocPosition.
Next, I think the value you're computing for the x coordinate is in the wrong direction. I think you want to use the negative of that.
I just want to add one more thing.
The code which Walter suggested does center the graph but it centers it horizontally AND vertically and I only needed it to be centerd horizontally, so no matter how long the document is the graph needs to always start at the top.
Thanks
Susan
I was having similar problems centering my tree. Make sure that if you create a view and add it to your form programatically that you actually set it's size (i.e. width and height) otherwise none of the advice given will work. To make things easier, I would add the actual controls provided by Northwoods to a custom tab in your Visual Studio 2005 toolbox and then drag the GoView onto the form. This will autogenerate everything for you.
Once that is done, you can then use the dock property and set it to something like "fill". Try that and let me know if it solves your problem.
When I implement the code u suggested I still see the tree in the upper left corner but I see the scrollBars reflecting it's actual position.
When I click on the document however I see the tree exactly as I need it to be so I am trying to find out how can I simulate the same thing in code.
I tried registering the click event in my constructor and then calling it from the place where I have the rest of the centering code but it did not do the trick.
So I am wondering what is happening when I click on the view that makes the tree center?
Could it be that it gets the focus and that is why it centers? I am not sure if that is the case because if I click on the scrollbar itself it does not do it (and I think clicking on the scrollbar should move the focus to that view but I might be wrong) .
You are running into the same exact issues I ran into the other week. I tried to see if there was a way to register click events on the scrollbar and the weird thing is that even though the GoDocument/GoView VerticalScrollbar and HorizontalScrollbar both inherit from Windows.Forms.Scrollbar they do not handle the click event. I found out that in the end my problem was that nowhere in my Visual Studio designer generated code were any values set for the size of my GoView.
Try this:
Make sure that you are not trying to load your GoDocument into your GoView before the GoView has been initialized in the constructor. In fact, I would create a totally separate method (maybe call it Setup() or something) that gets called from your form's class constructor.
_mainLayout.Network = null; // GoLayout has to have the residual memory cleared
_mainLayout.LayerSpacing = 10;
_mainLayout.DirectionOption = GoLayoutDirection.Down;
_mainLayout.PackOption = GoLayoutLayeredDigraphPack.Median;
_mainLayout.PerformLayout();
_mainLayout.LayoutNodesAndLinks();
//this line keeps the diagram at the upper left corner of the document
I do that because I want to re-layout the tree if a user clicks on a subgraph and it expands.
So the funny thing is that when I click on the view then the MouseCaptureChanged event fires up and executes the Layout_Graph code again (after it has been called once from the first place.)
If I call the Layout_Graph function twice from the first place though nothing happens....
Strange.......