Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic how to set some selected-nodes auto align(such as Left-Align.Center-Align. Top-Align) in Diagram? (Read 2194 times)
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
how to set some selected-nodes auto align(such as Left-Align.Center-Align. Top-Align) in Diagram?
Oct 13th, 2014 at 5:43am
Print Post  
hello,
    after I create some nodes in Diagram,then I selected some of them. and I want to set the Selected-Nodes auto align.
the align mode include left-align,right-align,center-align,top-align,bottom-align,Middle-align.
could you tell me is there some method to reach the effect?
thank!
  

1_003.jpg (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to set some selected-nodes auto align(such as Left-Align.Center-Align. Top-Align) in Diagram?
Reply #1 - Oct 13th, 2014 at 8:45am
Print Post  
Hi,

You can find some sample code here:
http://mindfusion.eu/Forum/YaBB.pl?num=1412696051

That code is for Windows Forms; replace all RectangleF with Rect and float with double to compile under WPF. Centering using the methods above will look like this:

Code
Select All
void AlignCenterX()
{
	Align(
		r => r.X + r.Width / 2,
		(r, coord) => new Rect(coord - r.Width / 2, r.Y, r.Width, r.Height));
}

void AlignCenterY()
{
	Align(
		r => r.Y + r.Height / 2,
		(r, coord) => new Rect(r.X, coord - r.Height / 2, r.Width, r.Height));
}

void Align(
	Func<Rect, double> getter,
	Func<Rect, double, Rect> setter)
{
	var target = diagram.ActiveItem as DiagramNode;
	if (target != null)
	{
		var alignedCoord = getter(target.Bounds);
		foreach (var node in diagram.Selection.Nodes)
		{
			if (node == target)
				continue;
			node.Bounds = setter(node.Bounds, alignedCoord);
		}
	}
}

void AlignLeft()
{
	Align(
		r => r.Left,
		(r, coord) => new Rect(coord, r.Y, r.Width, r.Height));
}

void AlignTop()
{
	Align(
		r => r.Top,
		(r, coord) => new Rect(r.X, coord, r.Width, r.Height));
}

void AlignRight()
{
	Align(
		r => r.Right,
		(r, coord) => new Rect(coord - r.Width, r.Y, r.Width, r.Height));
}

void AlignBottom()
{
	Align(
		r => r.Bottom,
		(r, coord) => new Rect(r.X, coord - r.Height, r.Width, r.Height));
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to set some selected-nodes auto align(such as Left-Align.Center-Align. Top-Align) in Diagram?
Reply #2 - Oct 13th, 2014 at 9:28am
Print Post  
thanks,It works.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint