Menu

#1 Layout, Simple Across and Down

open
nobody
None
5
2006-11-29
2006-11-29
Jim
No

For Each Shape
Put Each on the control, starting in top left corner
Continue Across the top, and if run out of room, move down
Note that the down movement is currently be the height of the LAST control

Code to do it:
void Layout_SimpleAcrossAndDown(object sender, LayoutEventArgs e)
{
// For Each Shape
// Put Each on the control, starting in top left corner
// Continue Across the top, and if run out of room, move down
// Note that the down movement is currently be the height of the LAST control
DiagramControlBase diagControl = e.AffectedComponent as DiagramControlBase;
if (diagControl != null)
{
#region Placeholder info
#region Min/Max of X and Y
int DisplayMinX = 0;
int DisplayMinY = 0;
int DisplayMaxX = diagControl.Width;
int DisplayMaxY = diagControl.Height;
#endregion
int iSpacerX = 20;
int iSpacerY = 20;
int iNextPlacementX = DisplayMinX;
int iNextPlacementY = DisplayMinY;
#endregion
// Loop through all shapes
foreach (ShapeBase shp in diagControl.Controller.Model.Shapes)
{
#region Deal with going past end of control, with this shape (Placing NOT totally inside)
if ((iNextPlacementX + shp.Width) >= DisplayMaxX)
{
iNextPlacementX = DisplayMinX;
iNextPlacementY += shp.Height + iSpacerY;
}
#endregion
// Move to Next X,Y coords
shp.Move(new Point(iNextPlacementX, iNextPlacementY));
#region Advance Draw Point to next position
iNextPlacementX += shp.Width + iSpacerX;
#region Deal with going past end of control
if (iNextPlacementX >= DisplayMaxX)
{
iNextPlacementX = DisplayMinX;
iNextPlacementY += shp.Height + iSpacerY;
}
#endregion
#endregion
// make sure shape knows it needs to be re-drawn
shp.Invalidate();
}
}
}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.