【发布时间】:2014-05-06 05:51:30
【问题描述】:
我有一个用户控件,上面有一个文本框。我不想根据字体大小更改控件大小,这样它就不会切断文本的底部,但是我对控件大小所做的更改根本没有效果。
public override Font Font
{
get
{
return base.Font;
}
set
{
textBox1.Font = base.Font = value;
if (Font.Height != this.Height)
this.Height = Font.Height;
}
}
protected override void OnResize(EventArgs e)
{
textBox1.Size = new Size(this.Width - (_textboxMargin * 2 + _borderWidth * 2), this.Height - (_textboxMargin * 2 + _borderWidth * 2));
textBox1.Location = new Point(_textboxMargin, _textboxMargin);
base.OnResize(e);
}
在设置属性后触发 OnResize 事件时,this.Height 保持原始值。
--编辑--
事实证明问题是我在控件大小之前设置了字体,所以它被覆盖了。但这发生在我使用此控件的页面的设计器中。我怎样才能防止这种情况在未来发生?
【问题讨论】:
标签: c# textbox custom-controls font-size