Support Forums > General Board

STATIC/LABEL control text alignment


Paul Squires:
I am pretty sure that with a standard Static control that you can *NOT* set the text alignment to be bottom/left, bottom/center, or bottom/right?

Here is the code I just wrote for the Label control in the new visual designer:

--- Code: ---   case "TEXTALIGN"
      AfxRemoveWindowStyle(pCtrl->hWindow, SS_CENTER)
      AfxRemoveWindowStyle(pCtrl->hWindow, SS_LEFT)
      AfxRemoveWindowStyle(pCtrl->hWindow, SS_RIGHT)
      AfxRemoveWindowStyle(pCtrl->hWindow, SS_CENTERIMAGE)
      dim as long wsStyle
      select case **wszPropValue
         CASE "LabelAlignment.MiddleCenter": wsStyle = SS_CENTER OR SS_CENTERIMAGE
         CASE "LabelAlignment.MiddleLeft":   wsStyle = SS_LEFT   OR SS_CENTERIMAGE
         CASE "LabelAlignment.MiddleRight":  wsStyle = SS_RIGHT  OR SS_CENTERIMAGE
         CASE "LabelAlignment.TopCenter":    wsStyle = SS_CENTER
         CASE "LabelAlignment.TopLeft":      wsStyle = SS_LEFT   
         CASE "LabelAlignment.TopRight":     wsStyle = SS_RIGHT 
      AfxAddWindowStyle(pCtrl->hWindow, wsStyle)
      SetWindowPos( pCtrl->hWindow, 0, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_DRAWFRAME)

--- End code ---

Would the only solution be to apply the SS_OWNERDRAW style and then handle the text alignment in WM_DRAWITEM? Then I could use the DrawText api with all of the flexibility of those drawing flags.

Paul Squires:
I have modified the Label control in WinFBE to use SS_OWNERDRAW so that now we can position the Label text using the DrawText api via WM_DRAWITEM.


[0] Message Index

Go to full version