C# 在不使控件最大化的情况下获取控件的最大大小,windows窗体
我有一个表单,其中包含picturebox(锚点设置为左、右、上、下)和一些其他控件,我想知道当表单最大化而不最大化表单时,是否仍有获取picturebox大小的方法C# 在不使控件最大化的情况下获取控件的最大大小,windows窗体,c#,winforms,C#,Winforms,我有一个表单,其中包含picturebox(锚点设置为左、右、上、下)和一些其他控件,我想知道当表单最大化而不最大化表单时,是否仍有获取picturebox大小的方法 [我必须根据picturebox的最大尺寸裁剪图像]有几种方法可以解决这个问题。 1.转到WPF。(Windows窗体越来越不推荐使用。) 2.在运行时使用反射获取picturebox的属性。 试着这样做: using System.Reflection; private PictureBox DoSomethingWithPro
[我必须根据picturebox的最大尺寸裁剪图像]有几种方法可以解决这个问题。 1.转到WPF。(Windows窗体越来越不推荐使用。) 2.在运行时使用反射获取picturebox的属性。 试着这样做:
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;
}
您必须使用屏幕的大小并使用一些计算,例如屏幕的宽度-(2*边框的宽度)等,以计算picturebox在不实际使其最大化的情况下可以达到的最大大小。@FizzBuzz,我认为当窗体最大化时,其他控件也会最大化,那么,有没有办法预测这些:-(您使用的是什么类型的
using
语句?是C#6.0
的新功能吗?