如果文本太长,C#将添加三点 [英] C# adding triple dot if text is too long

查看:74
本文介绍了如果文本太长,C#将添加三点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以可以说这是我的代码

so lets say this is my code

label1.text = "123456789";



我看到我只想看到最多5个,我想在我的标签上看到它

12345 ...

但我希望在不编辑label1的文本的情况下发生这种情况

例如,我不希望发生这种情况



and I see that I just want to only see up to 5, I wanna see this on my label

12345...

but I want this to happen without editing the the label1''s text

for example I don''t want this to happen

label1.text = "12345...";

>

我只希望它在将其加载到窗体上时看起来像这样,希望您理解我在说什么



I just want it to look like that when I load it on my form, I hope you understand what i''m talking about

推荐答案

设置标签的AutoEllipsis变为真实.

Set label''s AutoEllipsis to true.

label1.AutoEllipsis  = true;


string str = "123456789";

           if (str.Length > 5)
           {
             label1.Text = string.Concat(str.Substring(0, 5), "...");
           }
           else
           {
               label1.Text = str;
           }


这篇关于如果文本太长,C#将添加三点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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