C# 中使用 AutoSize 和 TextAlign 属性可使 Label 竖直显示:1. 设置 AutoSize 为 True;2. 设置 TextAlign 为 TopLeft。示例代码:label1.AutoSize = true;label1.TextAlign = ContentAlignment.TopLeft。根据需要调整 Font 和 Margin 等属性以微调外观。

C# 中 Label 如何竖直显示
在 C# 中,可以使用 AutoSize 和 TextAlign 属性使 Label 竖直显示。
步骤:
-
设置
AutoSize为 True- 这允许 Label 根据其内容自动调整大小。
-
设置
TextAlign为 TopLeft- 这将内容对齐到 Label 的左上角。
代码示例:
<code class="csharp">Label label1 = new Label(); label1.AutoSize = true; label1.TextAlign = ContentAlignment.TopLeft; label1.Text = "Vertical Label";</code>
注意事项:
- 确保容器中没有其他元素影响 Label 的垂直显示。
- 根据需要设置其他属性,例如
Font和Margin,以微调外观。










