Pregunta

I know to Inflate the Rectangle by Pixels, How to by Percentage?

Ex: rect.Inflate(45%,105%) the integer value should be passed as percent value not pixel value

How??

¿Fue útil?

Solución

One option is to use the SizeF structure to allow for you to calculate the width and height values by percentage values, like this:

SizeF theSize = new SizeF(rect.Width * .45, rect.Height * 1.05);

SizeF holds floating point values, but unfortunately there is no overload for Inflate() that accepts a SizeF, but it does have an overload that accepts a Size structure. So we need to convert a SizeF to a Size, like this:

// Round the Size
Size roundedSize = Size.Round(theSize);

// Truncate the Size
Size truncatedSize = Size.Truncate(theSize);

Finally, we can use our converted Size (either the rounded or truncated), like this:

rect.Inflate(roundedSize);

OR

rect.Inflate(truncatedSize);

Otros consejos

There is no function to do this. You will need to calculate the pixels from the percentage and use those instead.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top