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 中的项目正确对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!