防止在设计时调整高度尺寸

2024-04-12

我正在开发自定义用户控件。如何防止在设计时界面期间修改控件的仅高度。


您可以覆盖SetBoundsCore http://msdn.microsoft.com/en-us/library/system.windows.forms.control.setboundscore.aspx方法并不允许通过改变来改变高度height调用基类实现之前的值。

private const int FixedHeightIWantToKeep = 100;

protected override void SetBoundsCore(
    int x,
    int y,
    int width,
    int height,
    BoundsSpecified specified)
{
    // Fixes height at 100 (or whatever fixed height is set to).
    height = this.FixedHeightIWantToKeep;
    base.SetBoundsCore(x, y, width, height, specified);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

防止在设计时调整高度尺寸 的相关文章

随机推荐