2013-10-26 77 views
0

我知道Inflate矩形按像素,如何按百分比?按百分比膨脹矩形

例如:rect.Inflate(45%,105%)整數值應百分比值不是像素值

如何傳遞?

+1

'rect.Inflate(rect.Width * .45,rect.Height * 1.05);'雖然不精確... – 2013-10-26 14:47:33

+0

是的,我已經得到了...簡單的calc ..謝謝.. @ ebyrob –

回答

1

一種選擇是使用SizeF結構允許您通過百分比值計算的寬度和高度值,如:

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

SizeF持有浮點值,但遺憾的是沒有過載Inflate()接受SizeF,但它確實有一個接受Size結構的超載。因此,我們需要一個SizeF轉換爲Size,像這樣:

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

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

最後,我們可以用我們的轉換Size(無論是圓形或截斷),像這樣:

rect.Inflate(roundedSize); 

OR

rect.Inflate(truncatedSize); 
0

沒有這個功能。您需要從百分比中計算像素,然後使用它們。