Search code examples
c#formstextlistboxalignment

Need text box to display message on right side as well


I added a listbox control to log entries but I want the entries to have a date in the right side. Apparently, I'm able to only align it one side and not able to have this text on both the side. I was wondering if it is possible. Here's a photoshopped image to describe what I need. The right side date doesn't actually turn up. I added that through photoshop but its exactly what I need.enter image description here


Solution

  • I would like to suggest you to use ListView instead of Listbox. You can show your list with multiple columns in detail view. You can also align column value, Hide header using HeaderStyle property.

    If you don't want to use ListView control and want to use ListBox. then you have three options to do that.

    1. You can draw item using OwnerDraw method.
    2. You can add label to the ListBox. but, it creates lot of problems when you are trying to scroll items.
    3. Set the listbox font Courier New and use String.PadRight or String.PadLeft to place space between two item. But, in this method the item will be return with space. Here you need to process to separate that field.