Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Align Node Centers (Read 2099 times)
jlspublic
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 5
Joined: Sep 15th, 2011
Align Node Centers
Sep 15th, 2011 at 1:45pm
Print Post  
The AlignToGrid property can be used to align the top/left sides of diagram nodes. Is there a convenient way to get the centers aligned instead of the edges?

Thanks,
-JLS
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Align Node Centers
Reply #1 - Sep 15th, 2011 at 2:02pm
Print Post  
At this time you can do that from the NodeCreated or NodeModified event handlers. Call node.GetCenter(), pass the point to the Diagram.AlignPointToGrid method, and offset the node with the difference between the two points.

Btw. the version we are now releasing adds Visual Studio -like alignment guides that can be used to align nodes by their centers. You can try the beta build here, but we are releasing the official version today or tomorrow anyway:
https://mindfusion.eu/_beta/wpfdiag_alignmultisel.zip

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


I love YaBB 1G - SP1!

Posts: 5
Joined: Sep 15th, 2011
Re: Align Node Centers
Reply #2 - Sep 15th, 2011 at 6:23pm
Print Post  
Thanks, your suggestion worked great. I'm including my code here in case someone else wants to do the same thing.

''' <summary>
''' Snap center point of node to grid instead of top left corner.
''' </summary>
''' <param name="Target"></param>
''' <remarks>
''' This makes rows/columns of nodes look better if they are different sizes.
''' </remarks>
Private Sub AlignCenter(ByVal Target As DiagramNode)
Dim CenterPoint As Point = Target.GetCenter
Dim NearestGridPoint As Point = diaSchematic.AlignPointToGrid(CenterPoint)
Dim CurrentLocation As Point = Target.Bounds.TopLeft
Target.Move(CurrentLocation.X + (NearestGridPoint.X - CenterPoint.X), CurrentLocation.Y + (NearestGridPoint.Y - CenterPoint.Y))
End Sub


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