本文介绍了UserControl的大小由构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许标题不是很好 - 因此我尝试解释我的问题:

我经常创建自己的控件和/或用户控件。

全部我的控件是可扩展的。

在我的一些UserControls中,我在InitializeComponents-Call之后在Constructor-Script(New)中设置Size-Property为一个固定值(例如Mybase.size = new size (150,30))。将控件放入表单(例如)时,将完全忽略此设置。将它放在Form上后,可以随时调整Control的大小,此设置也存储在Form的Designer-Script中(或容器控件中)。



我在哪里犯这个错误?

Perhaps the title is not very good - therefore I try to explain my "problem" :
I often create my own Controls and/or UserControls.
All of my Control are scalable.
In some of my UserControls I set the Size-Property in the Constructor-Script (New) after the InitializeComponents-Call to a fixed value (for example Mybase.size = new size (150,30)). This setting is completly ignored when I put the Control to a Form (for example). After putting it on a Form it is all times possible to resize the Control and this setting is also stored in the Designer-Script of the Form (or in a Container-Control).

Where do I make the mistake ?

推荐答案

public class MyClass : UserControl {

    public MyClass {
        defaultSize = //... setup some fixed size
    }

    protected virtual Size DefaultMaximumSize {
        get { return this.defaultSize; }
    }
    protected virtual Size DefaultMinimumSize {
        get { return this.defaultSize; }
    }

    Size defaultSize;

    // ...

}



-SA



这篇关于UserControl的大小由构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 02:41