在设计时防止高度调整 [英] prevent height sizing at design time

查看:113
本文介绍了在设计时防止高度调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working on a custom user control. How can I prevent the HEIGHT ONLY of the control from being modified during the design-time interface.

推荐答案

您可以覆盖< a href = http://msdn.microsoft.com/zh-cn/library/system.windows.forms.control.setboundscore.aspx rel = nofollow noreferrer> SetBoundsCore 方法,并通过在调用基类实现之前更改 height 值来禁止更改高度。

You can override the SetBoundsCore method and disallow changes to height by changing the height value before calling the base class implementation.

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);
}

这篇关于在设计时防止高度调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆