Click here to Skip to main content
15,897,094 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to set length for each line in edit control?I am reading text from .txt file and displaying text in Edit Control.I've set the property of edit control as multiline but text which is displayed using SetWindowTextW() is not showing in proper format as in text file.I think there is problem with Length of each line.
Posted

1 solution

If you set the edit control as multi-line, then the way(s) to set the line size limit are:
(1) adding artificial "\r\n" line breaks (to make the line shorter)
(2) changing the font (size or typeface). A proportional font will display a different number of characters on each line, depending on line content. A non-proportional font will display the same number of characters on each line.
(3) resizing the control.

If a line you read in and try to display on the control is longer than the control will hold on one line, it will break the line and display the last part on the 'next' line.
 
Share this answer
 
Comments
Member 9796765 26-Feb-13 1:46am    
I am reading whole text file in CString object.After each line ends in text file I am appending CString object with "\r\n".After reading whole file in this way I am using SetWindowText () for displaying that cstring object but in edit control its not showing in proper format as in text file.BUT when I copy that text to clipboard and paste it in text file it is showing in a proper format.
H.Brydon 26-Feb-13 11:25am    
When you say "not showing in proper format" what does that mean? Is the font different? Is the font size different? Is the line length different? Are there different characters? Does the line wrap differently?

??
Member 9796765 26-Feb-13 23:41pm    
the line Wraps differently...
H.Brydon 27-Feb-13 0:01am    
I don't have a definitive answer but if you are reading from a text (ANSI?) file, the lines are somehow converted to Unicode, and if you insert copy/paste via the clipboard, there is likely some different control characters inserted somewhere. [If you are using SetWindowTextW() and not SetWindowTextA() then I assume you are reading 8 bit characters and managing wide characters in your program.]

The thing to do would be to get the edit control to dump (to the trace window) what it sees from each source.
Member 9796765 27-Feb-13 22:36pm    
I am using SetWindowsTextW().can you tell me the best way to read text from .txt file and show in a edit control..and thanks for your reply...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900