在使用 pictureBox1.SizeMode = PictureBoxSizeMode.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);
}

本文介绍了一种通过反射获取PictureBox在Zoom模式下实际显示位置和大小的方法。此方法适用于当PictureBox处于Zoom模式且需要获取精确显示尺寸的情况。
9073

被折叠的 条评论
为什么被折叠?



