为什么我不能将表格高度设置为30px?

时间:2012-08-31 03:31:47

标签: c# forms height

我试过设置它,但是当这个,我的表格仍然有更大的高度。有办法做到这一点吗?

5 个答案:

答案 0 :(得分:2)

A Note from MSDN:-

  

使用Sizable样式,无法调整窗口下方的窗口大小   某个最小值,即使您已将ControlBox设置为false和   为Text分配了一个零长度字符串。考虑解决这个问题   改为使用SizableToolWindow style

答案 1 :(得分:1)

您可能已将true设置为Form.AutoSize属性。关闭AutoSize=false

答案 2 :(得分:1)

我只能假设问题是边界风格 所有形式都有一个你不能改变的边界 如果你不介意没有边框只是将边框样式设置为none,那么表单高度甚至可以是0px

答案 3 :(得分:1)

使ControlBox = False;你会得到你想要的东西。因为ControlBox的大小超过30x30,没有它你可以做到所有尺寸。

答案 4 :(得分:1)

这是一个适合我的解决方案。

在从Form派生的类中,覆盖两个方法以绕过应用的大小修正,并禁止您将大小设置为低于限制。

    // the *real* width and height of your form, Width and Height are now lying...
    internal int CoreWidth { get; private set; }
    internal int CoreHeight { get; private set; }

    // just for fun :
    public new int Width { get { return CoreWidth; } }
    public new int Height { get { return CoreHeight; } }

    protected override void SetClientSizeCore ( int x, int y )
    {
        // get wished width and height earlier enough in the chain of calls
        CoreWidth = x;
        CoreHeight = y;
        base.SetClientSizeCore ( x, y );
    }

    protected override void SetBoundsCore ( int x, int y, int width, int height, BoundsSpecified specified )
    {
        // don't trust width and height that are provided, use the ones you kept
        base.SetBoundsCore ( x, y, CoreWidth, CoreHeight, specified );
    }

像魅力一样......我用它来创建某种通知窗口,可以在屏幕上的任何位置弹出,它可以包含任何类型的控件,并且具有任何大小,没有限制。