Ah I misread the question. Thanks for the clarification. I guess I didn't
box showing so I just read the 70 and went with that. You are right that a
lot depends on the character font, size, etc. which is often changeable by
the user if the programmer doesn't force it. I've often resized controls to
didn't think of that.
I think you are right. This is a more difficult design challenge than I
about this eventuality.
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
The problem is that the OP doesn't want to limit the input; the OP wants
to limit the line
length.
Picking a line length like 70 is difficult. It only works well if you
have a fixed-pitch
font.
Using a multiline control with ES_AUTOHSCROLL disabled will automatically
wrap lines, but
not apply magic such as 70.
In a world designed by people with a shred of design sense, the easy
solution would be to
intercept OnChar, and when the count is reached, first call
CEdit::OnChar(_T('\n'), ...)
but due to terminal brain-death in the MFC designers (some silliness
completely
unjustified by reality), you can't do this, sadly. But it can be
finessed, for example,
by doing a GetWindowText, appending a newline sequence, and doing a
SetWindowText of the
result.
joe
On Wed, 6 Jan 2010 10:20:46 -0800, "Tom Serface" <tom@camaswood.com>
wrote:
You can use SetLimitText() to set the number of characters in the
control...
http://msdn.microsoft.com/en-us/library/c4db48kc(VS.71).aspx
You will have to check any text that is added to the window with
SetWindowText() or UpdateData() before you do it to limit the string since
this only limits user typing.
You can also hook into OnChar and counting the characters that have been
typed as the user goes along. Then you can move to the next control at
the
appropriate time. You'll have to allow the user to go back and make
changes
(I'd guess) so you'll want to not move it just on the character count,
but,
perhaps, when they type the next character after the 70th???
http://msdn.microsoft.com/en-us/library/c4db48kc(VS.71).aspx
Tom
"David Wilkinson" <no-reply@effisols.com> wrote in message
news:uCUdFTtjKHA.1536@TK2MSFTNGP06.phx.gbl...
surjit bawa wrote:
Hello Friends,
Following is my requirement:
I have a dialog with multiline cedit control, I want to set the width
of
this cedit control and correspondingly update the width of parent
dialog
and the 2 buttons.
e.g I want to allow only 70 characters to be typed in each line of the
cedit control, after user has entered 70 characters cursor should move
to
next line. I do not want to use setmargins, only 70 characters should
be
visible to the user.
I have already disable horizontal scroll bar.
To get a wrapping CEdit:
Set ES_MULTILINE style
Do not set ES_AUTOHSCROLL style
To determine desired size you can use CDC::GetTextExtent(), and resize
in
OnInitDialog().
--
David Wilkinson
Visual C++ MVP
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm