Click here to Skip to main content
13,301,195 members (64,485 online)
Rate this:
Please Sign up or sign in to 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 24-Feb-13 19:02pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
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...
H.Brydon 28-Feb-13 9:49am
I haven't seen your code, but you are probably doing it in a reasonable way. You just need to be aware that you seem to be converting from 8 bit characters to 16 bit characters/Unicode and there are several ways for things to go awry in the process.

I suggest that you debug your program and get the edit control to do a report (ie. detailed dump to output with hex description of all characters) when you write info to the control with your program vs copy/paste through the clipboard.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171207.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100