sPanel and OnPaint – again

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #32778
    remsi
    Participant

    Hi!

    I have another issue regarding an sPanel with an OnPaint routine assigned.

    Deriving a class from sPanel I have a constructor like:

    CODE
    Constructor TMyPanel.Create(AOwner: TWinControl);
    begin
    inherited Create(AOwner);
    Parent := AOwner;
    Caption := 'I am a Panel';

    newButton := TsSpeedButton.Create(Self);
    newButton.Parent := Self;
    newButton.ShowHint := True;
    newButton.Hint := 'Hello';
    newButton.Caption := 'Hello';

    OnPaint := myPaint;

    The problem is, that in some situations myPaint draws over the button. I was able to reproduce this behaviour with myButton.ShowHint := True

    I also found out, that the panels caption is drawn correctly which led me to the following solution:

    CODE
    procedure TsPanel.OurPaint;
    var
    Canv: TCanvas; //Added this
    begin
    //some Code

    // The original code
    //if DC = 0 then WriteText(R, Canvas) else WriteText(R, nil, DC);
    //if Assigned(FOnPaint) then FOnPaint(Self, Canvas);

    // My changes
    if DC = 0 then
    begin
    Canv := Canvas;
    end
    else begin
    Canv := TCanvas.Create;
    Canv.Handle := DC;
    Canv.Font.Assign(Font);
    Canv.Brush.Style := bsClear;
    end;
    WriteText(R, Canv);
    if Assigned(FOnPaint) then FOnPaint(Self, Canv);

    if DC <> 0 then
    begin
    Canv.Free;
    end;

    Cheers,

    Clemens

    #41859
    Support
    Keymaster

    Hello Clemens and thanks for a code.
    You are right, a potential error was there, I'll research and change it.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.