c# - 从中心对称更新 WinForms 标签中的文本
问题描述
Label
如果这里的每一行都是值更新,而不是单个文本,首先显示“A”,然后显示“New”等,如何从中心对称更新 WinForms 控件中的文本:
A
New
Year
Comes
again
and again
to spread
the spirit and
Celebration have
a wonderful New Year
party and Happy New Year
with joy and peace
解决方案
使用 StringBuilder,标签的 TextAlign 属性设置为 MiddleCenter,AutoSize 设置为 true。
StringBuilder sb = new StringBuilder();
sb.AppendLine("A");
sb.AppendLine("New");
sb.AppendLine("Year");
sb.AppendLine("Comes");
sb.AppendLine("again");
sb.AppendLine("and again");
sb.AppendLine("to spread");
sb.AppendLine("the spirit and");
sb.AppendLine("Celebration have");
sb.AppendLine("a wonderful New Year");
sb.AppendLine("party and Happy New Year");
sb.AppendLine("with joy and peace");
Label l = new Label();
l.AutoSize = true;
l.TextAlign = ContentAlignment.MiddleCenter;
l.Text = sb.ToString();
Controls.Add(l);
推荐阅读
- .net - filehelper 库是否能够读取 xml 文件
- kotlin - 在扩展 Parceable 密封类的对象上使用 android-extensions 的 Parcelize 注释
- mpdf - 带有隐藏和边距标题的 Mpdf 7 分页 html 错误
- c# - 从所有 Excel 工作表中创建一个数组
- r - Surface Pro 4 上的“xlsx”“无法创建 Java 虚拟机”的 .onLoad 失败
- javascript - Javascript:在承诺中解决和拒绝的目的是什么?
- sql-server - 使用 Sqlite 进行 EF Core DbContext 测试并在生产中使用 SQL Server
- jquery - 带有 JQueryValidation 的表单不运行 validate() 函数
- javascript - Trouble connecting to blue-tooth devices using node noble on Windows
- centos7 - repmgr - Automate process of making primary to standby after failover