Delphi tcustomcontrol/twincontrol

1.6k views Asked by At

Can someone please explain me which control is better to create custom componens? What is the difference between twincontrol and tcustomcontrol?

Thank you in advance

1

There are 1 answers

2
Remy Lebeau On BEST ANSWER

Can someone please explain me which control is better to create custom componens?

That depends on what kind of component you are making and what its requires are.

Is it visual?

  • If no, use TComponent.

  • if yes, does it need its own HWND (input focus, window messages, etc)?

    • If no, use TGraphicControl.

    • If yes, does it need to custom paint itself?

      • if yes, use TCustomControl.

      • if no, use TWinControl.

What is the difference between twincontrol and tcustomcontrol?

TCustomControl is a TWinControl descendant that adds some additional handling for the WM_PAINT message, on top of what TWinControl does. TCustomControl exposes a public Canvas property that you can draw on. During painting, it enables the csCustomPaint flag in the ControlState property, and then calls a virtual Paint() method that your component can override. So the benefit of TCustomControl is that it makes custom painting a little easier to manage. Nothing more.