Control.GetPreferredSize(Size) 方法

定義

擷取可容納控制項之矩形區域的大小。Retrieves the size of a rectangular area into which a control can be fitted.

public:
 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

參數

proposedSize
Size

控制項的自訂大小區域。The custom-sized area for a control.

傳回

Size 類型的排序配對,代表矩形的寬度與高度。An ordered pair of type Size representing the width and height of a rectangle.

實作

System.Windows.Forms.Layout.IArrangedElement.GetPreferredSize(System.Drawing.Size)

備註

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)). 例外狀況是0或 Size.EmptyproposedSize,其定義為無限制。The exception is a proposedSize of 0 or Size.Empty, which are defined as unconstrained.

適用於