News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Align vertical text (Edit control)

Started by ragdog, May 15, 2016, 02:54:03 AM

Previous topic - Next topic

ragdog

Hello all

I use a Flat Edit control height 12 but the text is not vertical Aligned.



Have your any solution or idea?

Regards,

jj2007

EM_SETMARGINS doesn't work for you, but you have five other choices:

1. bigger text
2. control less high
3. EM_SETRECT
4. EM_SETRECTNP
5. draw it yourself

If all that doesn't help, use a RichEdit control and set it via SetParaFormat, hEdit, PFM_SPACEBEFORE
;)

fearless

For multiline edit control the EM_SETRECTNP and EM_SETRECT would work, but for singeline it wont - only EM_SETMARGINS which only handles left and right margins.

Came across this example whilst looking into creating a singleline vertically centered edit control last week: http://www.codeguru.com/cpp/v-s/devstudio_macros/textoperations/article.php/c8491/Vertical-Text-Centering-in-an-Edit-Control.htm

It uses WM_NCCALCSIZE to readjust the controls region rect to place it vertically centered, and then paints (in WM_NCPAINT) the top rectangle and bottom rectangle of the edit control with the standard brush to fake this effect.

I converted it to asm after some work, but the only problem i came across with this is that the mouseover is no longer recognised for being over the control when mouse is over the top and bottom rectangle, although still fires fine for the actual text and caret part of the control (which has been adjusted in WM_NCCALCSIZE) - would be fine for most uses that dont need the WM_MOUSEMOVE to be fired when over the control.

I have a specific requirement that needed that so i started working on a hosted edit control as a child control in a container - bit more work to forward on specific messages from container to the internal edit control, but it does allow the container to calc the vertically center for the child control to be placed at once it is created.



Ive attached my example using the WM_NCCALCSIZE method - Click mouse on lower part of the back square to get caret, and start typing - you will see that i use the mouseover to change the background of the edit control and the text color when mouse is over the control or not - the top rectangle part isnt seen as part of the control anymore (from the mousemove point of view) and as such it doesnt fire this event when over that part of the edit control, but does when over the bottom two-thirds of the black edit control)

jj2007

Looks a bit complicated. What about the attached example, see line 36 and 49ff?

ragdog

#4
Thank you both for your nice examples :t

I really good idea. it same what i have found yesterday a cpp example.

A other question is is it posible to draw if select a text (blue) change to a other color?

Greets,
raggy

Edit:

EM_SETRECT works only with Multiline but i need only a single line

@Jochen How did you make this that the multiline not works?