C# 獲取PictureBox的SizeMode為Zoom圖形的大小
轉載https://blog.csdn.net/qq_28249373/article/details/75947856
轉載https://blog.csdn.net/zgke/article/details/4372246
C# 獲取PictureBox的SizeMode為Zoom圖形的大小
可以通過反射ImageRectangle 屬性獲取最後顯示的大小..
方法
/// <summary>
/// 獲取PictureBox在Zoom下顯示的位置和大小
/// </summary>
/// <param name="p_PictureBox">Picture 如果沒有圖形或則非ZOOM模式 返回的是PictureBox的大小</param>
/// <returns>如果p_PictureBox為null 返回 Rectangle(0, 0, 0, 0)</returns>
public Rectangle GetPictureBoxZoomSize(PictureBox p_PictureBox)
{
if (p_PictureBox != null)
{
PropertyInfo _ImageRectanglePropert = p_PictureBox.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
return (Rectangle)_ImageRectanglePropert.GetValue(p_PictureBox, null);
}
return new Rectangle(0, 0, 0, 0);
}