获得最大的控件大小而不是最大化它,Windows窗体

时间:2013-10-17 23:45:44

标签: c# winforms

我有一个包含picturebox的形式(Anchor设置为Left,Right,Top和Bottom)以及其他一些控件,我想知道无论如何都要在窗体最大化时获得图片框的大小而不是最大化表格,

[我必须根据图片框的最大尺寸裁剪图像]

1 个答案:

答案 0 :(得分:0)

有几种方法可以解决这个问题。 1.转到WPF。 (Windows窗体已被弃用。) 2.使用反射在运行时获取图片框的属性。 尝试这样的事情:

using System.Reflection;
private PictureBox DoSomethingWithProperties(PictureBox picturebox)
{
    Type pictureboxType = picturebox.GetType();
    PictureBox instance = (PictureBox)Activator.CreateInstance(pictureboxType)
    // The above code is only used to create an instance of the picturebox type. 
    // This will enable modification/changes to the picturebox property values during runtime via late-binding.
    PropertyInfo DefaultSize= instance.GetType().GetProperty("DefaultSize", BindingFlags.Public | BindingFlags.Instance);
    PropertyInfo ClientSize= instance.GetType().GetProperty("ClientSize", BindingFlags.Public | BindingFlags.Instance);
    PropertyInfo DefaultMaximumSize= instance.GetType().GetProperty("DefaultMaximumSize", BindingFlags.Public | BindingFlags.Instance);
    return instance;
}