How can we vertically align text in edit box?

I don’t have enough reputation to make a comment, so here’s a possibly useful snippet to a very old question!

If you supply the WS_BORDER style then the text gets automatically vertically centred, as requested. Since the OP is using WS_EX_CLIENTEDGE, a border is drawn anyway, so adding in this style shouldn’t be a problem.

However, WS_BORDER | WS_EX_CLIENTEDGE only achieves a “partial” vertical centring.

Using WS_BORDER | WS_EX_STATICEDGE achieves the proper, vertical centring, although obviously then we have a slightly different visual style to the client-edged style. For me, I could live with this minor trade-off, rather that write a custom edit control.

Leave a Comment