How to use a TControlCanvas in a component
type
TScrollingPaintBox = class(TScrollingWinControl)
private
FCanvas: TCanvas;
public
constructor Create(aOwner: TComponent); override;
destructor Destroy; override;
property Canvas: TCanvas read FCanvas;
end;
constructor TScrollingPaintBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCanvas := TControlCanvas.Create;
TControlCanvas(FCanvas).Control := Self;
end;
destructor TScrollingPaintBox.Destroy;
begin
FCanvas.Free;
inherited Destroy;
end;
A TControlCanvas is important because it creates a DC (device context) that belongs to the HWND of the control. Also, override is important on your constructor and destructor to ensure that they are actually called.
本文介绍如何在自定义组件中使用TControlCanvas。通过创建TScrollingPaintBox类并覆盖构造函数与析构函数来实现设备上下文(DC)与窗口句柄(HWND)的绑定。
2万+

被折叠的 条评论
为什么被折叠?



