Force resize node to integer values

I have GoSimpleNodes that I allow the user to resize and reshape. I need to force the result of the resize to be integer values. I have tried in several places but to no avail. What is the preferred method to accomplish this?

Do you want the node size to be integer, or the shape? The Shape gets resized, but a label outside the shape will add some non-integer factor.



Are you using grids?

The shape needs to be an integer value. I am not using a grid, but I am open to using one if it makes life easier.

Well, limited testing, but this seems to work:



[Serializable]

class GoSimpleInt: GoSimpleNode {



public override void LayoutChildren(GoObject childchanged) {

if (childchanged == this.Icon) {

this.Icon.Width = (float)Math.Round(this.Icon.Width);

this.Icon.Height = (float)Math.Round(this.Icon.Height);

}

base.LayoutChildren(childchanged);

}

}



Note it doesn’t help to override DoResize on the node, as the object getting the DoResize is the Icon/Image object. You could subclass that object and handle DoResize there, but this is a little quicker to code.



Actually (after our email about this) I was wondering why you just don’t truncate the width/height as your are doing the export to XML…

Jake,

Thanks for you help. I am now able to force the width and height to integer values. I also need to force the location, top and left, to integer values. I have not yet been able to fix that issue yet. The GoSimpleNodes I subclass have a rectangle, icon, and a label. The interaction between them is what I think is causing me grief. I think I should summarize what I am trying to do and repost.
Regarding truncation exporting to xml, the user can see the values in the propertygrid. So, I would prefer to make them appear the same as what gets saved to xml.
Thanks again,
John

node.Location defaults to SelectionObject.Center.



You could turn on Grid to get rounded off Location, but beware that doesn’t mean all the other parts of the node will also be “integer”.