根据子标签的大小更改表单的大小

发布于 2025-01-13 08:14:03 字数 75 浏览 3 评论 0原文

如何根据标签的宽度/长度更改表单大小?

我需要根据标签中有多少文本来调整表单的大小(文本是从 case 语句自动生成的)。

How would you change the Form size depending on the width/length of a Label?

I need to resize a Form depending on how much text there is in a Label (the text is automatically generated from case statements).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明媚如初 2025-01-20 08:14:03

您可以尝试将FormAutoSize设置为True

打开Form并在其上放置Label,标签有一个名称,比如Label1
输入图片此处描述

右键单击​​表单并打开“属性”
输入图片此处描述

然后选择 AutoSize 为 True

在此处输入图像描述

然后返回到表单并双击表单,本例中为 Form1,Form1.vb 打开。

Form1_Load 中,如果它是另一个标签,则必须将其调整为正确的名称:

  Label1.Text = "This is a example text and a bit longer zo the form is getting bigger"

在此处输入图像描述

运行它,它就在那里:

在此处输入图像描述

看这里 https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form.autosize?view=windowsdesktop-6.0

You can try to put the AutoSize to True of the Form

Open the Form and put a Label on it , the Label gets a Name lets say Label1.
enter image description here

Rightclick on the Form and open Properties
enter image description here

Then Choose AutoSize to True

enter image description here

Then return to the Form and dubbleclick on the Form this case Form1, Form1.vb is open.

In Form1_Loadif it is another Label you have to adjust it to the right Name:

  Label1.Text = "This is a example text and a bit longer zo the form is getting bigger"

enter image description here

Run it and there it is :

enter image description here

Look here https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form.autosize?view=windowsdesktop-6.0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文