Windows Develop Bookmark and Share   
 index > Windows Forms General > textproblem
 

textproblem

Hello, I've got a problem with showing a textfile in a correct manner. Blank characters makes my "columns" that I have made with blank characters/tabs. Let me show what I meen...

my textfile:


text    mjukdjur   datum
                       9999-66-33
                       9999-66-33

 


Now everything is fine, but when I try to put the text inte a control my "columns" is "corrupt". I've tried a listbox and textbox. In a control it looks like this:


text    mjukdjur   datum
                  9999-66-33
                  9999-66-33

 
In my example (controlexample). The number och blank characters from the left to 9999 is the same as in the real textfile (I just took some away to demostrate..
Finally the code for binding the control:

StreamReader reader = new StreamReader("163400.0002", Encoding.Default);
while (!reader.EndOfStream)
{
    string str = reader.ReadLine();
    Console.Out.WriteLine(str);
    richTextBox1.Text += str + '\n';
    listBox1.Items.Add(str);
}
reader.Close();

 
Can someone please tell me what to do, I realy need to show the user the propper "columns".

Best regards
Carl-Otto  Wednesday, September 14, 2005 6:01 PM
It looks like you are running into a display difference between fixed-width fonts (e.g. Courier New) and proportional width fonts (e.g. Arial).

Try changing the Font name you are using for your listbox to "Courier New" and see if that helps.
Paul Laudeman  Wednesday, September 14, 2005 8:50 PM
It looks like you are running into a display difference between fixed-width fonts (e.g. Courier New) and proportional width fonts (e.g. Arial).

Try changing the Font name you are using for your listbox to "Courier New" and see if that helps.
Paul Laudeman  Wednesday, September 14, 2005 8:50 PM
Depending on exactly what you want to accomplish, you may find it useful to have a ListView with the View property set to Details instead of a list box or text box to display your data.

This would allow you to add the appropriate columns, but of course you'd have to parse the input in order to figure out what to put in the respective columns.

Best regards/med vänliga hälsningar,
Johan Stenberg
MSFT Johan Stenberg  Wednesday, September 14, 2005 9:18 PM

The listbox would also give you some additional benefits in enabling sorting on the different columns as well.  

Something a standard listbox or textbox wouldnt allow you to do easily.

I love the listview, although I really would like just a simple multicolumn listbox control - there are so many places it would come in handy for simple alignment purposes.


spotty  Thursday, September 15, 2005 2:10 AM
Thank you for all replies, but the only thin I would whant to do with my text is to show it to the user as it is in the file. It helped with changing the font

regards
Carl-Otto  Thursday, September 15, 2005 5:11 AM

You can use google to search for other answers

Custom Search

More Threads

• Writing a Flash Blocker
• How to intercept of binding data when design custom control?
• Missing Attribute on Exchange 2007 Server Object
• Adding strings with quotes to datagrid
• Draw pie or bar graphs???
• Secure Desktop Application
• Changing font sizes in code
• BufferedGraphicsContext cannot be disposed of because a buffer operation is currently in progress.
• The comboBox displays 0 instead of data
• PowerStatus