Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3697702
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:53:32+00:00 2026-05-19T04:53:32+00:00

Hi all I made a new component derived from TWinControl . I put it

  • 0

Hi all
I made a new component derived from TWinControl.
I put it on a TPanel and I tried to call the PaintTo procedure of the panel. The result is the panel and its caption and my component is not painted on the canvas at all. What should I do about this?

a part of the source (as dear David asked):

Procedure TApListBox.Paint;
var
  C: TCanvas;
  B: TBitmap;
  ItemClient: TPoint;
Begin
  Try
    If (FUpdating > 0) Then
      Exit;
    Try
      BeginUpdate;
      B := TBitmap.Create;
      B.Width := Width;
      B.Height := Height;
      With B.Canvas Do Begin
        Lock;
        // Begin :
        ItemClient := Point(IVisPanel + 3, 2);

        // Draw Items
        PaintItems(B.Canvas, ItemClient);
        Unlock;
      End;

      C := TCanvas.Create;
      C.Handle := GetWindowDC(Self.Handle);
      C.Lock;
      inherited;
      C.Draw(1, 1, B);
      If (RenameEdit.Visible) Then
        RenameEdit.Repaint;
    Finally
      C.Unlock;
      ReleaseDC(0, C.Handle);
      C.Free;
      B.Free;
      Dec(FUpdating);
    End;
  Except
  End;
End;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:53:32+00:00Added an answer on May 19, 2026 at 4:53 am

    In your method handling the WM_PAINT message, you can NOT use the Canvas directly, because WM_PAINT specify a GDI handle (HDC) in the Message.DC parameter.

    Take a look, for example, at this code snippet from TGraphicControl, which handle it as expected:

    procedure TGraphicControl.WMPaint(var Message: TWMPaint);
    begin
      if Message.DC <> 0 then
      begin
        Canvas.Lock;
        try
          Canvas.Handle := Message.DC;
          try
            Paint; // this is where the painting is done, using a "locked" Canvas
          finally
            Canvas.Handle := 0;
          end;
        finally
          Canvas.Unlock;
        end;
      end;
    end;
    

    So check your WM_PAINT implementation method, and follow this code scheme.

    Instead of the “Paint” method above, put your own drawing code using the Canvas property.

    The “PaintTo” method will work as expected.

    Another possibility is to use direct Windows API drawings, using the Message.DC handle… but I guess the above method, allowing the use of a regular Canvas, is more easy for most of us! 😉

    In all cases, WM_PAINT shouldn’t be the place where Delphi components implement the painting, but only an overridden Paint method. So let your component inherits from TGraphicControl, and put all the drawing code into an overridden Paint method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just create a new MVC project, and have made no changes at all,
All the recent VisualSVN Server posts made me want to check it out. I
Our development policy dictates that all database accesses are made via stored procedures, and
I have a component that is made up of various components such as a
I made a new repository, and ran git add -A . I then noticed
I have just started learning MVVM. I've made the application from scratch by following
All the articles I've found via google are either obsolete or contradict one another.
All front-end developers know the pain of coding for Firefox, then viewing our then
All I know about the constraint is it's name ( SYS_C003415 ), but I
All I want is to be able to change the color of a bullet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.