Change form size at runtime in C#

前端 未结 6 1734
傲寒
傲寒 2021-01-01 19:32

How can I change window form size at runtime?

I saw examples, but every one requires Form.Size property. This property can be set like here: http://msdn.microsoft.co

6条回答
  •  -上瘾入骨i
    2021-01-01 19:51

    As a complement to the answers given above; do not forget about Form MinimumSize Property, in case you require to create smaller Forms.

    Example Bellow:

    private void SetDefaultWindowSize()
    {
       int sizeW, sizeH;
       sizeW = 180;
       sizeH = 100;
    
       var size = new Size(sizeW, sizeH);
    
       Size = size;
       MinimumSize = size;
    }
    
    private void SetNewSize()
    {
       Size = new Size(Width, 10);
    }
    

提交回复
热议问题