找到你要的答案

Q:Resize width on Windows Forms C#

Q:调整Windows窗体上的C #宽度

I'm somewhat new to coding and I'm making an application in Windows Forms C#.

What I want to do is resize some of the forms depending on the length of a string. It's doing a calculation with some inputs, and if the output can't all be seen in the form I want it to be resized.

I have done this so far, but it doesn't seem to work:

public Form3(int age, string name)
        {
            InitializeComponent();
            Variables.age = age;
            Variables.name = name;

            if (Variables.length > 22)
            {
                this.Width = Variables.length * 5;
            }
        }

我有些新的编码我利用在Windows窗体应用程序的C #。

我想做的是根据字符串的长度调整一些窗体的大小。这是一些投入做一个计算,如果输出不能看到形式我要调整。

到目前为止,我做了这件事,但似乎不起作用:

public Form3(int age, string name)
        {
            InitializeComponent();
            Variables.age = age;
            Variables.name = name;

            if (Variables.length > 22)
            {
                this.Width = Variables.length * 5;
            }
        }
answer1: 回答1:

This is the whole point that the AutoSize property was created. It will enable dynamic growing and shrinking based on your form's content. Also, it has several different modes.

这是AutoSize属性产生的点。它将使您的窗体内容的基础上动态增长和缩小。此外,它有几种不同的模式。

c#