prevent height sizing at design time

别说谁变了你拦得住时间么 提交于 2019-12-23 20:01:08

问题


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.


回答1:


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



回答2:


You can override the Height attribute from the Control class and then set the BrowsableAttribute to prevent it from being displayed in the properties windows

You can also take a look at Attributes and Design-Time Support



来源:https://stackoverflow.com/questions/1537417/prevent-height-sizing-at-design-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!