We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to keep the view centered after zoom

Hi,

After changing diagram magnification property diagram orogin is the same as it was before. So, if user click zoom in button several times, diagram view moves to the left top corner of the diagram.

But I want to keep the view centered on the same diagram poin as it was before.

There are several solutions published on this forum how to center to the selected node, but if nothing is selected things seems to be more compolicated.

How can I do this?

3 Replies

MW Melba Winshia Syncfusion Team April 7, 2010 01:07 PM UTC

Hi Witold,

Thank you for your interest in Syncfusion Products.

You can use the following code to display the view to the center of the diagram control.

[c#]
float locationX = (diagram1.Width - diagram1.View.Width) / 2;
float locationY = (diagram1.Height - diagram1.View.Height) / 2;
this.diagram1.View.Origin = new PointF(-locationX, -locationY);


Please let me know if this helps.

Thanks,
Melba



WS Witold Slirz April 8, 2010 11:13 AM UTC

I tried, but it does not work.

ZoomIn event handler looks like this:

private void ButtonZoomPlus_Click(object sender, EventArgs e)
{
if (_activeDiagram != null)
{
_activeDiagram.View.Magnification += 25.0f;
float locationX = (_activeDiagram.Width - _activeDiagram.View.Width) / 2;
float locationY = (_activeDiagram.Height - _activeDiagram.View.Height) / 2;
this._activeDiagram.View.Origin = new PointF(-locationX, -locationY);
}
}

It seems that Diagram.View.Height and Diagram.View.Width should change values after zooming in or out, but they dont. Diagram.View.Origin is the same all the time, despite visible area became smaller after zooming. Thus, after several zoom in iterations visible area moves to the left up corner of the diagram.


MW Melba Winshia Syncfusion Team April 13, 2010 12:48 PM UTC

Hi Witold,

Currently it is not possible to keep the view centered while zooming if nothing is selected. We tried for a workaround to solve this issue, but it seems to be more complicated and we are not able to achieve the accurate solution. So this has been confirmed as a Feature Request. We will implement this feature in our forthcoming new version releases or service pack releases. We usually have an interval of at least three months between releases. The feature implementation would also greatly depend on the factors such as product design, code compatibility and complexity. We will get back to you once the feature is implemented.

Please let me know if you have any concerns.

Regards,
Melba

Loader.
Live Chat Icon For mobile
Up arrow icon