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);