From: surjit on
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.

Kindly help.

REgards
Surjit


Submitted via EggHeadCafe - Software Developer Portal of Choice
SQL Server XML and .Net Serialization
http://www.eggheadcafe.com/tutorials/aspnet/53200c7b-9d17-49ff-a713-23b94b8824df/sql-server-xml-and-net-s.aspx
From: David Wilkinson on
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
From: Tom Serface on
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(a)effisols.com> wrote in message
news:uCUdFTtjKHA.1536(a)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

From: Joseph M. Newcomer on
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(a)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(a)effisols.com> wrote in message
>news:uCUdFTtjKHA.1536(a)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(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Tom Serface on
Ah I misread the question. Thanks for the clarification. I guess I didn't
think that someone would want to limit the characters to the length of the
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
fit the screen or limited the number of characters (of any type or size),
but never tried to fit it to what is only showing on the screen so I just
didn't think of that.

I think you are right. This is a more difficult design challenge than I
originally thought and I don't think the designers of Window or MFC thought
about this eventuality.

Tom

"Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message
news:ujp9k5ddfqes1c0okpq3b319g7t45chnl4(a)4ax.com...
> 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(a)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(a)effisols.com> wrote in message
>>news:uCUdFTtjKHA.1536(a)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(a)flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm