7

I have created an editbox as:

m_EditWnd.Create(m_hWnd, rect, NULL, ES_LEFT | ES_AUTOHSCROLL | WS_CHILD |
                                     WS_OVERLAPPED | WS_VISIBLE,
                 WS_EX_CLIENTEDGE | WS_EX_LEFT | WS_EX_LTRREADING);

There is a style for horizontal alignment as ES_CENTER for horizontal text alignment, but can we align text vertically centered?

poundifdef
  • 18,726
  • 23
  • 95
  • 134

2 Answers2

3

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.

dicksters
  • 106
  • 5
1

I tried the solution from @Aidan Ryan with a small adjustment to avoid another the issue related to UI. I move the "SetWindowPos" into the OnNCPaint() and invoke the function only once time.