Search code examples
c#winformsloggingtextboxpadleft

I cannot display Logs in a Textbox aligned


I am creating log files for my application. When I display the Logs in a Textbox, they dont look aligned even though there are same amount of characters. I use PadLeft function to align everyline but doesnt when I try to display them in textbox. But they look good when I open the log files in EditPlus editor.

here is my log files text...

02 Ocak 2015 Cuma 16:22:21      FİŞ NO: SNT_CKS                   SONUÇ: BAŞARILI
02 Ocak 2015 Cuma 16:23:42      FİŞ NO: SNT_CKS                   SONUÇ: Kayıt veritabanına aktarılamadı., 
02 Ocak 2015 Cuma 16:24:01      FİŞ NO: A.HIZ.                    SONUÇ: Kayıt veritabanına aktarılamadı., 
02 Ocak 2015 Cuma 16:24:01      FİŞ NO: D.ALIS.B                  SONUÇ: Kayıt veritabanına aktarılamadı.,

here is my Log lines in textbox...

enter image description here

I think whitespaces and regular characters dont have the same width and it displays terrible in textbox. Is there way to fix this?


Solution

  • Use a fixed-width font in your TextBox.

    The log text aligns by padding the text with extra whitespace characters, so each of your columns start at same character index. TextBox by default has a proportional font (Which is typical in UI applications), where narrow characters like I, for instance, don't take up as much horizontal space as W. This also means that we can't use character-counting for aligning things, unless we use a fixed-width font.

    You can set the font on the TextBox by setting the Font property.