Equally outlining listbox values in C# with the PadLeft function

前端 未结 2 1542
旧巷少年郎
旧巷少年郎 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: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.

提交回复
热议问题