【发布时间】:2012-12-09 04:53:36
【问题描述】:
我正在尝试调整自定义面板控件的大小,使其在宽度上适合父容器。当我检查控件值时,它们都是相同的,但是子控件对于父控件来说太宽了。
造成这种差异的原因是什么?我希望能够计算出正确的尺寸。我尝试更改填充和边距选项,但这没有任何效果。
[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;
}
}
}
【问题讨论】: