Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic DiagramView Auto scrolling to 0, 0 diagram location (Read 3259 times)
rnpayet
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 7
Joined: Nov 14th, 2011
DiagramView Auto scrolling to 0, 0 diagram location
Jul 18th, 2012 at 2:29am
Print Post  
Hi
We are having issue with DiagramView.

When we do a zoomToFit we get the diagram to center in the view are we want to.

As soon as the diagram is re size e.g    via a node drag.  The diagram jumps and align left .

It there any way of preventing this


  

Zoom_to_fit_-ok.png (Attachment deleted)
resize-realingn.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DiagramView Auto scrolling to 0, 0 diagram location
Reply #1 - Jul 18th, 2012 at 10:11am
Print Post  
Hi,

At this time the only way to prevent that is to set diagram.Bounds to be at least as large as the view.

Stoyan
  
Back to top
 
IP Logged
 
jf2020
Junior Member
**
Offline


I love FlowChart!

Posts: 63
Joined: Feb 23rd, 2006
Re: DiagramView Auto scrolling to 0, 0 diagram location
Reply #2 - Jul 23rd, 2012 at 3:23pm
Print Post  
Stoyan,

Can you please elaborate a bit more on this answer and explain what the various properties Bounds, viewport, extent, in diagram and diagramView mean exactly and how they behave.  I have tried to implement something similar where I want the drawing area to always be in the middle of the visible area when zooming out (i.e. I don't want 0,0 to stay at the upper left corner) similar to Power Point but I have had lots of trouble with this.  So A good explanation would be very welcomed.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DiagramView Auto scrolling to 0, 0 diagram location
Reply #3 - Jul 24th, 2012 at 6:15am
Print Post  
Resizing the diagram to fill the view after calling ZoomToFit can be implemented like this:

Code
Select All
private void zoomToFitToolStripMenuItem_Click(object sender, EventArgs e)
{
	diagram.ResizeToFitItems(5);
	diagramView.ZoomToFit();

	// center diagram in view
	RectangleF bounds = diagram.Bounds;
	RectangleF viewport = diagramView.ClientToDoc(diagramView.ClientRectangle);
	PointF diagCenter = GetCenter(bounds);
	diagramView.ScrollTo(
		diagCenter.X - viewport.Width / 2,
		diagCenter.Y - viewport.Height / 2);

	// make sure diagram fills view
	float dx = 0, dy = 0;
	if (viewport.Width > bounds.Width)
		dx = (viewport.Width - bounds.Width) / 2;
	if (viewport.Height > bounds.Height)
		dy = (viewport.Height - bounds.Height) / 2;
	bounds.Inflate(dx, dy);
	diagram.Bounds = bounds;
}

PointF GetCenter(RectangleF r)
{
	return new PointF(r.X + r.Width / 2, r.Y + r.Height / 2);
} 



This will zoom preserving the on-screen position of the specified document point; you can use the diagram center instead of mouse position if you need to keep the diagram centered:

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
 
jf2020
Junior Member
**
Offline


I love FlowChart!

Posts: 63
Joined: Feb 23rd, 2006
Re: DiagramView Auto scrolling to 0, 0 diagram location
Reply #4 - Jul 24th, 2012 at 5:16pm
Print Post  
Stoyan,

Many thanks for the fast answer. I'll try this ASAP and let you know how it goes.

JF
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint