Announcement

Collapse
No announcement yet.

Problems Redrawing a Transparent Label - found two solutions: which is best?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems Redrawing a Transparent Label - found two solutions: which is best?

    I recently had a problem redrawing text in a transparent label control. Setting text in the label the first time worked well, however, when trying to update the label with new text the original text wasn't getting erased.

    BTW: the transparent label repainted correctly when I resized my form. When resizing the form I basically use MoveWindow, then InvalidateRect.

    I found two solutions and am wondering which is considered best practice?

    I'm also interested to learn why RedrawWindow and InvalidateRect when applied to the control itself don't seem to work when trying to force a transparent label to repaint. I suspect the answer is given in the stack overflow link below where the person posting that question said: "..it seems the problem is the controls parent (the form) is responsible for drawing the background. This means that when you change the label text, the control redraws the new text, BUT the form doesn't automatically redraw the background."

    method 1 (works derived by me)
    Code:
    'do this before repainting text in the transparent label, not needed when initially painting text 
    ShowWindow(ctrlhwnd,%SW_HIDE)
    showwindow(ctrlhwnd,%SW_SHOW)
    method 2 (also works)
    Code:
    'or do this before repainting text in the transparent label, not needed when initially painting text
    'this solution from the below link
    'https://stackoverflow.com/questions/1823883/updating-text-in-a-c-win32-api-static-control-drawn-with-ws-ex-transparent  (found after I discovered the above solution)
    LOCAL trect AS rect
    GetClientRect(ctrlhwnd, trect)
    InvalidateRect(ctrlhwnd, trect, %TRUE)
    MapWindowPoints(ctrlhwnd,parenthwnd, trect, 2)
    RedrawWindow(parenthwnd, trect, %NULL, %RDW_ERASE OR %RDW_INVALIDATE)
    Which method is preferred?

    Are there better ways to force a transparent label to repaint?

    Comments? Suggestions?



  • #2
    method 2
    Code:
    GetClientRect(ctrlhwnd, trect)
    InvalidateRect(ctrlhwnd, trect, %TRUE)
    I think the best way is the second method, but after InvalidateRect either do nothing (it will be painted sometime) or force repaint using UpdateWindow.
    Wilko

    Comment

    Working...
    X