[英]child control larger than parent when width equal
我正在嘗試調整自定義面板控件的大小,以便它在寬度方面適合父容器。 當我檢查控件值時,它們都是相同的,但是對於父控件,子控件太寬。
是什么導致了這種差異? 我希望能夠計算出正確的尺寸。 我嘗試更改填充和邊距選項,但這沒有任何影響。
[Category("Collapsible Panel")]
[DesignOnly(true)]
[DefaultValue(false)]
[Description("If True, fits the panel to match the parent width")]
public bool FitToParent
{
get { return _fitToParent; }
set {
_fitToParent = value;
if (_fitToParent)
{
if (this.Parent != null)
{
this.Location = new Point(0, this.Location.Y);
this.Size = new Size(this.Parent.Size.Width, this.Size.Height);
this.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
}
}
else
{
this.Anchor = AnchorStyles.Top | AnchorStyles.Left;
}
}
}
使用表單和控件的ClientSize
。
control.ClientSize.Width
form.Width
或control.Width
是包含邊框的外部寬度。 ClientRectangle
是可以放置其他控件的邊框之間的內容, ClientSize
是此內部矩形的大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.