How to disable automatic painting for TLabel?

66 Views Asked by At

I have a TForm with a TTreeView and a TPanel, where the Panel is associated with a TLabel.

In my TTreeView, there are nodes with text that is too long to be fully displayed, so a scrollbar is automatically generated. Since my TLabel serves as a header, I use TextOutA to print my label every time the position of the TTreeView changes.

All of this is already working; however, I now face the issue that the Label seems to be redrawn when I shift the focus from my application to my second monitor, resulting in incorrect display.

Does anyone have an idea on how to possibly solve this problem?

void __fastcall TShortView2Form::HeadlineDrawing(void)
{
    TRect LabelRect;

    LabelRect = TitelLabel->ClientRect;
    TitelLabel->Canvas->Brush->Color = Panel1->Color;
    LabelRect.Left = DefaultLeftPosition - 20;
    TitelLabel->Canvas->FillRect(LabelRect);  // Fill the Pannel, with his Background Color, therefore                     it is blank

    LabelRect.Left = DefaultLeftPosition - 20; // -20, for the Correct Position of the Drawing
    TitelLabel->Canvas->Font->Color = clBlack;
    TitelLabel->Canvas->Font->Style += TitelLabel->Canvas->Font->Style << fsBold;
    TitelLabel->Canvas->TextOutA(LabelRect.Left, LabelRect.Top, TitelLabel->Caption);

    TitelLabel->Canvas->Font->Style -= TitelLabel->Canvas->Font->Style << fsBold;
}

void __fastcall TShortView2Form::TreeView1AdvancedCustomDrawItem(TCustomTreeView *Sender,
    TTreeNode *Node, TCustomDrawState State, TCustomDrawStage Stage,
    bool &PaintImages, bool &DefaultDraw)
{
    bool bHeadlineDraw = true;
    if (Node->Level == 0)
    {
        TRect Rect;
        Rect = Node->DisplayRect(true);

        if (DefaultLeftPosition != Rect.Left)
        {
            DefaultLeftPosition = Rect.Left;

            if (Stage == cdPostPaint)
            {
                HeadlineDrawing();
                bHeadlineDraw = false;
            }
        }
    }

    Sender->Canvas->Brush->Color = clWhite;
    Sender->Canvas->Font->Color = clBlack;

    bool bIsSelected = State.Contains(cdsFocused);
    if (bIsSelected && bHeadlineDraw && Stage == cdPostPaint)
    {
        HeadlineDrawing();
        bHeadlineDraw = false;
    }
}

My Form normally looks like this:

Form with the right look

This is what my Form looks when I switch to my second screen:

Form with false look

I have already tried checking, if there are any changes when I invoke the Headlinedrawing() function in the OnPaint event of the TForm. However, this doesn't make any difference.

I have also verified that my function doesn't print the text in the wrong place for confirmation, but this is not the case, either.

0

There are 0 best solutions below