Can#39;t make the items in a ListBox align correctly using TabStops(无法使用 TabStops 使 ListBox 中的项目正确对齐)
问题描述
ListbBox 有以下问题.
I have the following problem with ListbBox.
为了便于理解,我做了一些简化.
To make it easy to understand I have simplified it a bit.
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("xxxxxx" +" "+ "yyyyyyy");
listBox1.Items.Add("xxxxxxx" + " " + "yyyyyyy");
listBox1.Items.Add("xxxxxxxx" + " " + "yyyyyyy");
listBox1.Items.Add("xxxxxxxxx" + " " + "yyyyyyy");
listBox1.Items.Add("xxxxxxxxxx" + " " + "yyyyyyy");
}
}
从第 1 行到第 4 行,它以直线向下完美地打印出来.但是当我运行程序时,第 5 行完全关闭了,虽然有足够的空间.任何人都可以帮我把所有物品都排成直线向下吗?
From row 1 to 4 it prints out perfectly in straight rows downwards. But the 5th row is completly off when I run the program, although there is plenty of space. Can any body help me to get all items to be in straight rows downwards?
推荐答案
需要设置属性CustomTabOffsets 和属性 UseCustomTabOffsets 然后您可以将字符串中的制表符数量减少到只有一个.
You need to set the property CustomTabOffsets and the property UseCustomTabOffsets and then you can reduce the number of tabs in your strings to only one.
例如
ListBox lb = new ListBox();
lb.Size = new Size(500, 200);
lb.CustomTabOffsets.Add(100);
lb.UseCustomTabOffsets = true;
lb.Items.Add("xxxxxx" + " " + "yyyyyyy");
lb.Items.Add("xxxxxxx" + " " + "yyyyyyy");
lb.Items.Add("xxxxxxxx" + " " + "yyyyyyy");
lb.Items.Add("xxxxxxxxx" + " " + "yyyyyyy");
lb.Items.Add("xxxxxxxxxx" + " " + "yyyyyyy");
Form f = new Form();
f.Controls.Add(lb);
f.Show();
当然,您应该将 100 更改为与字符串第一部分的实际最大长度和 ListBox 的宽度更一致的值
Of course you should change that 100 to something more consistent with the actual maximum length of the first part of your strings and the width of your ListBox
这篇关于无法使用 TabStops 使 ListBox 中的项目正确对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法使用 TabStops 使 ListBox 中的项目正确对齐


基础教程推荐
- 如何激活MC67中的红灯 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- MS Visual Studio .NET 的替代品 2022-01-01