Text corrupted on TStatusBar while setting style to "OwnerDraw"

75 Views Asked by At

I used TStatusBar and set style to "psOwnerDraw" to fill custom color on it.

There is no problem to display text in normal case but after I changed the resolution on Windows or moved application out of screen and back, the text is corrupted with some other text.

Here's my code:

void __fastcall TMainForm::TotalStatusBarDrawPanel(TStatusBar * StatusBar,
    TStatusPanel * Panel, const TRect & Rect)
{
    TRect StatusFillRect = Rect;
    TCanvas& pCan = *StatusBar->Canvas;
    if (Panel->Index == 0)
    {
        pCan.Font->Color = clRed;
        pCan.Brush->Color = clBtnFace;
    }
    pCan.FillRect(StatusFillRect);

    DrawTextW(pCan.Handle, Panel->Text.c_str(), -1,
            &StatusFillRect, DT_SINGLELINE | DT_VCENTER);
}

Picture of StatusBar corrupted

0

There are 0 best solutions below