Control.GetPreferredSize(Size) Control.GetPreferredSize(Size) Control.GetPreferredSize(Size) Control.GetPreferredSize(Size) Method


检索适合控件的矩形区域的大小。Retrieves the size of a rectangular area into which a control can be fitted.

 virtual System::Drawing::Size GetPreferredSize(System::Drawing::Size proposedSize);
public virtual System.Drawing.Size GetPreferredSize (System.Drawing.Size proposedSize);
abstract member GetPreferredSize : System.Drawing.Size -> System.Drawing.Size
override this.GetPreferredSize : System.Drawing.Size -> System.Drawing.Size
Public Overridable Function GetPreferredSize (proposedSize As Size) As Size


Size Size Size Size

控件的自定义大小的区域。The custom-sized area for a control.


类型为 Size 的有序对,表示矩形的宽度和高度。An ordered pair of type Size representing the width and height of a rectangle.


的行为GetPreferredSize因控件而异。The behavior of GetPreferredSize differs by control. LayoutEngine可能无法将返回的大小分配给控件。The LayoutEngine might be unable to assign the returned size to the control. 你可以返回比proposedSize参数中指示的约束大的大小,但proposedSize应在约束减少时减小。You can return a size larger than the constraints indicated in the proposedSize parameter, but proposedSize should decrease as the constraint decreases. 例如, GetPreferredSize(new Size(100, 0))不应大于GetPreferredSize(new Size(200, 0))For example, GetPreferredSize(new Size(100, 0)) should not be wider than GetPreferredSize(new Size(200, 0)). 异常是proposedSize 0 或Size.Empty的,定义为不约束。The exception is a proposedSize of 0 or Size.Empty, which are defined as unconstrained.