News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How to vertically center a text in an Edit control?

Started by gwapo, April 19, 2006, 03:06:11 AM

Previous topic - Next topic

gwapo

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

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

gwapo

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

Mincho Georgiev

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]

zooba

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

gwapo

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


hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php