The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: gwapo on April 19, 2006, 03:06:11 AM

Title: How to vertically center a text in an Edit control?
Post by: gwapo on April 19, 2006, 03:06:11 AM
Hi,

Do you guys know what window style to apply to make Edit control (or possibly in RichTextBox control as well) to center its text vertically?


Thanks,

-chris
Title: Re: How to vertically center a text in an Edit control?
Post by: hutch-- on April 19, 2006, 03:10:31 AM
Chris,

When you create the rich edit control, the normal styles are supposed to work fine.

ES_CENTER
ES_RIGHT
ES_LEFT
ES_MULTILINE


This gives you normal horizontal alignment but I doubt there is a way to do this vertically unless you simply pad the start with enough CRLF pairs.
Title: Re: How to vertically center a text in an Edit control?
Post by: gwapo on April 19, 2006, 07:46:38 AM
Thanks hutch for the info.

Since there's no window style that will allow me to center text vertically, I was thinking that I have to adjust the non-client area instead, based on the window height and Font height (since I am only working with single line text).

Regards,

-chris
Title: Re: How to vertically center a text in an Edit control?
Post by: Mincho Georgiev on April 22, 2006, 10:13:37 AM
Hi gwapo! I don't know what exactly you working on , but sometimes is better to use a static or custom control for just printing a centered text if that is the case.
I had remember a particular case , and i've made that example for you, you can use the same method to center the text in any control (Edit, Rich...) or you can just use anything for 'posting' a centered text.
Greets!



[attachment deleted by admin]
Title: Re: How to vertically center a text in an Edit control?
Post by: zooba on April 23, 2006, 12:22:20 AM
I don't have any MASM example, but since you are working with a single line of text, make the textbox without a border and use a static control with a border to make it look the size you want. I use this trick all the time in VB, but it'd be quite a bit more complicated to do in assembly methinks.

Cheers,

Zooba :U
Title: Re: How to vertically center a text in an Edit control?
Post by: gwapo on May 08, 2006, 06:28:42 AM
Quote from: shaka_zulu on April 22, 2006, 10:13:37 AM
Hi gwapo! I don't know what exactly you working on , but sometimes is better to use a static or custom control for just printing a centered text if that is the case.
I had remember a particular case , and i've made that example for you, you can use the same method to center the text in any control (Edit, Rich...) or you can just use anything for 'posting' a centered text (input and textarea control).
Greets!


Thanks shaka_zulu, your sample was a great help. What I'm currently working is a small library for Windowless Programming (actually a small Window Manager to be precise, the same way web-browsers draw and make the controls functional on a webpage) -- I thought it would be best to start with the simpliest which is a single line of text.

This is the same reason why I'm asking if there's a window style of vertical alignment, because I am implementing window styles as well for the small window manager I'm working on. Meaning, if there's ES_LEFT style for a window class, then instead of creating the window, then I am just drawing the window, hence the program may become lighter.

My only problem is implementing both client-area and non-client-area for the windowless program.

Regards,

-chris

Title: Re: How to vertically center a text in an Edit control?
Post by: hutch-- on May 08, 2006, 01:50:03 PM
Chris,

There is another approach if you don't mind controlling text from a WM_PAINT message and that is the DrawText() API which has a number of very useful text formatting styles including an edit control style of wordwrap. I would be inclined to point it at a back buffer and blit it onto the client area but you can control different areas of the text you wish to display by the rectangle co-ordinates you specify.