Equally outlining listbox values in C# with the PadLeft function

牧云@^-^@ 提交于 2019-12-02 08:54:24

To fix your immediate issue, just use a fixed-width font in the ListBox:

listBox1.Font = new Font(FontFamily.GenericMonospace, listBox1.Font.Size);

Now your padding logic will work as you expect:

Consider Hans's point though; check into controls that already display multiple columns of data, like the ListView or a DataGridView.

What you're experiencing is a result of the fact that the font is not "fixed width", so some characters are wider than other characters.

The list box control is not really designed to display multiple columns, which is really what it seems like you are looking for here. I would suggest you use a System.Windows.Forms.DataGridView instead.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!