Windows 窗体:如果文本太长,则在标签上添加新行 [英] Windows Forms: add new line to label if text is too long

查看:32
本文介绍了Windows 窗体:如果文本太长,则在标签上添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 C#.有时,从 Web 服务返回的文本(我显示在标签中)太长,会在表单的边缘被截断.如果不适合表单,是否有一种简单的方法可以在标签中添加换行符?

I'm using C#. Sometimes the text returned from a web service (which I display in a label) is too long and gets cut off on the edge of the form. Is there an easy way to add a newline to the label if it's not going to fit on the form?

谢谢

推荐答案

如果您将标签设置为 autosize,它将随着您放入的任何文本而自动增长.

If you set the label to autosize, it will automatically grow with whatever text you put in it.

为了使其在特定宽度自动换行,您可以设置 MaximumSize 属性.

In order to make it word wrap at a particular width, you can set the MaximumSize property.

myLabel.MaximumSize = new Size(100, 0);
myLabel.AutoSize = true;

经过测试并有效.

如果您希望始终能够看到数据,可以将 Label 容器的 AutoScroll 属性设置为 true.

If you always want to be able to see the data, you can set the Label's container's AutoScroll property to true.

这篇关于Windows 窗体:如果文本太长,则在标签上添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆