Question

I'm having undesirable reflexes with ES_AUTOHSCROLL Set.

What I'm trying to do is create an Edit that resizes with the text in it. However I hit a problem whenever the user types past the end of the edit.

Without ES_AUTOHSCROLL the user cannot type past the current size of the edit, so my edit doesn't grow to fit the new character, because input is ignored.

With ES_AUTOHSCROLL when the user types past the current size of the edit, it scrolls first before I get a chance to increase my window size, so I end up with the first letter hidden even though the window is now big enough to hold the new character.

My solution was to make my edit one max-width character longer than the text its holding and that works, because you have room to type the next character. However, that looks a little tacky.

If there was a way to allow wider text than the width of the edit window without using ES_AUTOHSCROLL I'd be set.

Was it helpful?

Solution 2

I found a way to simulate the effect I want.

I use ES_AUTOHSCROLL.

I respond to OnUpdate and change the size of the control to fit the text it contains. To handle the scrolling problem (it scrolls to insert text before it knows it will get bigger), still inside OnUpdate, I select 0,0, then return the previous selection. That way it scrolls back to the beginning, then updates the size.

This way the control appears to grow indefinitely without scrolling.

OTHER TIPS

I think you also want to use ES_MULTILINE

EDIT: In the documentation of CEdit there is a member function void CEdit::LimitText( int nChars = 0 ) which sets the text length to UINT_MAX. I still think you also need to use ES_AUTOHSCROLL (otherwise you'll get EN_MAXTEXT notifications when you try to type beyond the width of the control).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top