Equally outlining listbox values in C# with the PadLeft function

前端 未结 2 1541
旧巷少年郎
旧巷少年郎 2021-01-26 09:46

I am wrestling with my listbox and values in the listbox for some time now and I stumbled across another problem.

I am fetching data from my Access database (both the f

相关标签:
2条回答
  • 2021-01-26 10:20

    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.

    0 讨论(0)
  • 2021-01-26 10:29

    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:

    enter image description here

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

    0 讨论(0)
提交回复
热议问题