Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Question to Zoom functionality (Read 7259 times)
SJahr
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Dec 8th, 2006
Question to Zoom functionality
Dec 8th, 2006 at 7:26am
Print Post  
Hi,

i have a question to the zoom functionality of your FlowChart.NET control. At the moment zooming starts at the upper left corner of the visible part of my control. How can i realize that zooming starts at my mouse pointer position?

regards

Steffen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Question to Zoom functionality
Reply #1 - Dec 8th, 2006 at 8:38am
Print Post  
Hi,

It might be possible to do that using ZoomToRect. Zoom to a RectangleF centered around the mouse position, so that it is larger than the current visible area if you wish to zoom out, or smaller than it if you wish to zoom in.

You can get the document coordinates of the visible area and the mouse like this:

RectangleF visible = fc.ClientToDoc(fc.ClientRectangle);
PointF mousePos = fc.ClientToDoc(fc.ScreenToClient(MousePosition));

Then create a new RectangleF from [mousePos - visible.size / 2] to [mousePos + visible.size / 2], call its Inflate() method with a positive value to zoom out or a negative one to zoom in, and finally call the flowchart's ZoomToRect() method.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
SJahr
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Dec 8th, 2006
Re: Question to Zoom functionality
Reply #2 - Dec 8th, 2006 at 9:51am
Print Post  
Sorry, but your suggestion doesn't work. My flowchart doesn't contain an definition for the method 'ScreenToClient'. I have the latest version of flowchart.NET

regards

Steffen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Question to Zoom functionality
Reply #3 - Dec 8th, 2006 at 11:26am
Print Post  
Sorry, I meant PointToClient.

Stoyan
  
Back to top
 
IP Logged
 
SJahr
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Dec 8th, 2006
Re: Question to Zoom functionality
Reply #4 - Dec 8th, 2006 at 11:47am
Print Post  
I have tried to implement the zooming on using the mouse wheel. But i have always problems with it. but i didn't see my error.
My zoom jumps over the screen, but didn't zoom to the mouse position...

Quote:
void flowChart_MouseWheel(object sender, MouseEventArgs e)
     {
        RectangleF visible = flowChart.ClientToDoc(flowChart.ClientRectangle);
        PointF mousePos = flowChart.ClientToDoc(flowChart.PointToClient(MousePosition));

        RectangleF newRect = new RectangleF(mousePos.X- visible.Size.Width / 2, mousePos.Y - visible.Size.Height / 2, mousePos.X + visible.Size.Width / 2, mousePos.Y + visible.Size.Height / 2);
        if (e.Delta > 0)
        {
           newRect.Inflate(1.5f, 1.5f);
        }
        else
        {
           newRect.Inflate(-1.5f, -1.5f);
        }
        flowChart.ZoomToRect(newRect);
        
     }
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Question to Zoom functionality
Reply #5 - Dec 8th, 2006 at 11:52am
Print Post  
The RectangleF constructor takes (x,y,width,height) arguments. Try that with visible.Size.Width and visible.Size.Height as values for the last two parameters.

Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Question to Zoom functionality
Reply #6 - Dec 8th, 2006 at 11:56am
Print Post  
But maybe we use a wrong approach here. This will bring the location under the mouse point to the center of the control's visible area. And probably you want that point to remain at the same place while zooming in or out?
  
Back to top
 
IP Logged
 
SJahr
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Dec 8th, 2006
Re: Question to Zoom functionality
Reply #7 - Dec 8th, 2006 at 11:58am
Print Post  
Excellent support. It works fine. Thank you.

regards

Steffen
  
Back to top
 
IP Logged
 
liakix
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Jan 26th, 2012
Re: Question to Zoom functionality
Reply #8 - Jan 26th, 2012 at 12:58pm
Print Post  
Hello to everyone in the forum!

Quote:
But maybe we use a wrong approach here. This will bring the location under the mouse point to the center of the control's visible area. And probably you want that point to remain at the same place while zooming in or out?


Well, 5 years after the last post on this thread i'm having exactly the issue described at the quoted text. Is there any solution to this?

Thanks in advance,
Aimilios
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Question to Zoom functionality
Reply #9 - Jan 26th, 2012 at 2:56pm
Print Post  
Hi,

Try this if you need the diagram point at current mouse position to remain at the same position after zoom:

Code
Select All
private void OnMouseWheel(object sender, MouseEventArgs e)
{
	PointF docPointAtMousePos = diagramView.ClientToDoc(e.Location);

	int factorToIncrese = e.Delta * SystemInformation.MouseWheelScrollLines / 120;
	diagramView.ZoomFactor += factorToIncrese;

	PointF newPointAtMousePos = diagramView.ClientToDoc(e.Location);
	diagramView.ScrollX -= newPointAtMousePos.X - docPointAtMousePos.X;
	diagramView.ScrollY -= newPointAtMousePos.Y - docPointAtMousePos.Y;
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
liakix
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Jan 26th, 2012
Re: Question to Zoom functionality
Reply #10 - Jan 27th, 2012 at 7:45am
Print Post  
Problem solved, it works like a charm!

Thanks Stoyo,
Aimilios
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint