From: surjit on
Hello,
Thank you for replying to the post.

but my actual query is to 'I want to set the width of this cedit control and correspondingly update the width of parent dialog and the 2 buttons. based on the number of characters i want to in each line' , I believe this approach might be helpful as my cedit control is multiline, and horizontal scroll is disabled. and cedit will automatically take care of max text when user has reached the width end.

Only logic needed here is to calculate the width based on characters and font size of the system and correspondingly resize the cedit and parent dialog

Thanks and Regards
Surjit




Tom Serface wrote:

Ah I misread the question. Thanks for the clarification.
06-Jan-10

Ah I misread the question. Thanks for the clarification. I guess I did not
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 does not force it. I have 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
did not think of that.

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

Tom

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
..NET Managing more than one connection string from Web.config
http://www.eggheadcafe.com/tutorials/aspnet/75ef0837-dae2-4424-b7d0-48d4f23f78ca/net-managing-more-than-o.aspx
From: David Ching on
"surjit bawa" wrote in message news:20101701328surjit.bawa(a)in.com...
> Hello,
> Thank you for replying to the post.
>
> but my actual query is to 'I want to set the width of this cedit control
> and correspondingly update the width of parent dialog and the 2 buttons.
> based on the number of characters i want to in each line' , I believe this
> approach might be helpful as my cedit control is multiline, and horizontal
> scroll is disabled. and cedit will automatically take care of max text
> when user has reached the width end.
>
> Only logic needed here is to calculate the width based on characters and
> font size of the system and correspondingly resize the cedit and parent
> dialog
>

To calculate the width, in pixels, of 70 characters, use
CDC::GetTextExtent(). You need to use a fixed spaced font (like Courier
New) so that each character takes the same width as any other. Otherwise,
in proportional spaced fonts, characters like '1' take less space than fat
characters like '8'. You can use the SetFont() method to set a proportional
spaced font.

-- David


From: Tom Serface on
I agree with David that using GetTextExtent() would be the way to go. You
can change the font by setting the font for the control and resize the
control using either MoveWindow():

http://msdn.microsoft.com/en-us/library/5bc5w1zz(VS.80).aspx

Or SetWindowPos():

http://msdn.microsoft.com/en-us/library/a1yzfz6d(VS.80).aspx

When you create a font for the CEdit control make sure it exists for the
life of the control (like make it a member variable in the edit control
class).

You can use a function like:

http://msdn.microsoft.com/en-us/library/aa279839(VS.60).aspx

To create the font, but use a monospaced typestyle like "Courier" instead of
Arial (as David suggests).

Tom

"surjit bawa" wrote in message news:20101701328surjit.bawa(a)in.com...
> Hello,
> Thank you for replying to the post.
>
> but my actual query is to 'I want to set the width of this cedit control
> and correspondingly update the width of parent dialog and the 2 buttons.
> based on the number of characters i want to in each line' , I believe this
> approach might be helpful as my cedit control is multiline, and horizontal
> scroll is disabled. and cedit will automatically take care of max text
> when user has reached the width end.
>
> Only logic needed here is to calculate the width based on characters and
> font size of the system and correspondingly resize the cedit and parent
> dialog
>
> Thanks and Regards
> Surjit
>
>
>
>
> Tom Serface wrote:
>
> Ah I misread the question. Thanks for the clarification.
> 06-Jan-10
>
> Ah I misread the question. Thanks for the clarification. I guess I did
> not
> 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 does not force it. I have 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
> did not think of that.
>
> I think you are right. This is a more difficult design challenge than I
> originally thought and I do not think the designers of Window or MFC
> thought
> about this eventuality.
>
> Tom
>
> Previous Posts In This Thread:
>
>
> Submitted via EggHeadCafe - Software Developer Portal of Choice
> .NET Managing more than one connection string from Web.config
> http://www.eggheadcafe.com/tutorials/aspnet/75ef0837-dae2-4424-b7d0-48d4f23f78ca/net-managing-more-than-o.aspx

From: Joseph M. Newcomer on
Unless you have a fixed-pitch font, you must set the width for the widest possible line
you might get. Typically, in the Roman alphabet, this would be the width of 70 W
characters, but for other fonts, Your Mileage Will Definitely Vary; for example, in some
languages three "characters" might actually overlap each other. This gets into deep
complexities.

Or, you can dynamically resize it on the fly, although I would think this might be
visually disturbing if the user typed in 70 letter i characters on one line, then 70 A
characters on the second line, and 70 W characters on the third line. But there is NO WAY
to predict how wide "70 characters" is going to be in a variable-pitch font! So either
you keep doing dynamic adjustments or you size to maximum-possible-worst-case.
joe

On Wed, 06 Jan 2010 21:13:33 -0800, surjit bawa wrote:

>Hello,
>Thank you for replying to the post.
>
>but my actual query is to 'I want to set the width of this cedit control and correspondingly update the width of parent dialog and the 2 buttons. based on the number of characters i want to in each line' , I believe this approach might be helpful as my cedit control is multiline, and horizontal scroll is disabled. and cedit will automatically take care of max text when user has reached the width end.
>
>Only logic needed here is to calculate the width based on characters and font size of the system and correspondingly resize the cedit and parent dialog
>
>Thanks and Regards
>Surjit
>
>
>
>
>Tom Serface wrote:
>
>Ah I misread the question. Thanks for the clarification.
>06-Jan-10
>
>Ah I misread the question. Thanks for the clarification. I guess I did not
>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 does not force it. I have 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
>did not think of that.
>
>I think you are right. This is a more difficult design challenge than I
>originally thought and I do not think the designers of Window or MFC thought
>about this eventuality.
>
>Tom
>
>Previous Posts In This Thread:
>
>
>Submitted via EggHeadCafe - Software Developer Portal of Choice
>.NET Managing more than one connection string from Web.config
>http://www.eggheadcafe.com/tutorials/aspnet/75ef0837-dae2-4424-b7d0-48d4f23f78ca/net-managing-more-than-o.aspx
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
Yikes, resizing the control as the person types would be a nightmare and a
lot more ugly than a monospaced font.

Tom

"Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message
news:c90ck550kts6dk4vbfrd5iut1ank95itib(a)4ax.com...
> Unless you have a fixed-pitch font, you must set the width for the widest
> possible line
> you might get. Typically, in the Roman alphabet, this would be the width
> of 70 W
> characters, but for other fonts, Your Mileage Will Definitely Vary; for
> example, in some
> languages three "characters" might actually overlap each other. This gets
> into deep
> complexities.
>
> Or, you can dynamically resize it on the fly, although I would think this
> might be
> visually disturbing if the user typed in 70 letter i characters on one
> line, then 70 A
> characters on the second line, and 70 W characters on the third line. But
> there is NO WAY
> to predict how wide "70 characters" is going to be in a variable-pitch
> font! So either
> you keep doing dynamic adjustments or you size to
> maximum-possible-worst-case.
> joe
>
> On Wed, 06 Jan 2010 21:13:33 -0800, surjit bawa wrote:
>
>>Hello,
>>Thank you for replying to the post.
>>
>>but my actual query is to 'I want to set the width of this cedit control
>>and correspondingly update the width of parent dialog and the 2 buttons.
>>based on the number of characters i want to in each line' , I believe this
>>approach might be helpful as my cedit control is multiline, and horizontal
>>scroll is disabled. and cedit will automatically take care of max text
>>when user has reached the width end.
>>
>>Only logic needed here is to calculate the width based on characters and
>>font size of the system and correspondingly resize the cedit and parent
>>dialog
>>
>>Thanks and Regards
>>Surjit
>>
>>
>>
>>
>>Tom Serface wrote:
>>
>>Ah I misread the question. Thanks for the clarification.
>>06-Jan-10
>>
>>Ah I misread the question. Thanks for the clarification. I guess I did
>>not
>>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 does not force it. I have 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
>>did not think of that.
>>
>>I think you are right. This is a more difficult design challenge than I
>>originally thought and I do not think the designers of Window or MFC
>>thought
>>about this eventuality.
>>
>>Tom
>>
>>Previous Posts In This Thread:
>>
>>
>>Submitted via EggHeadCafe - Software Developer Portal of Choice
>>.NET Managing more than one connection string from Web.config
>>http://www.eggheadcafe.com/tutorials/aspnet/75ef0837-dae2-4424-b7d0-48d4f23f78ca/net-managing-more-than-o.aspx
> Joseph M. Newcomer [MVP]
> email: newcomer(a)flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm