604
社区成员




TRect rt( Left, Top, Left + Width, Top + Height );
Canvas->Brush->Color = clWhite;
Canvas->FrameRect( rt );
rt.left++;
rt.top++;
rt.right--;
rt.bottom--;
Canvas->Brush->Color = clBlack;
Canvas->FrameRect( rt );
rt.left++;
rt.top++;
rt.right--;
rt.bottom--;
Canvas->Brush->Color = clWhite;
Canvas->FrameRect( rt );
HDC dc = GetDC( Parent->Handle );
TBrush *pBrush = new TBrush;
pBrush->Style = bsClear;
TPen *pPen = new TPen;
pPen->Color = clWhite;
SelectObject( dc, pBrush->Handle );
SelectObject( dc, pPen->Handle );
Rectangle( dc,
Left,
Top,
Left + Width,
Top + Height );
pPen->Color = clBlack;
SelectObject( dc, pPen->Handle );
Rectangle( dc,
Left + 1,
Top + 1,
Left + Width - 1,
Top + Height - 1 );
pPen->Color = clWhite;
SelectObject( dc, pPen->Handle );
Rectangle( dc,
Left + 2,
Top + 2,
Left + Width - 2,
Top + Height - 2 );
ReleaseDC( Parent->Handle, dc );
delete pBrush;
delete pPen;
constructor TGraphicControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCanvas := TControlCanvas.Create;
TControlCanvas(FCanvas).Control := Self;
end;
procedure TControlCanvas.CreateHandle;
begin
if FControl = nil then inherited CreateHandle else
begin
if FDeviceContext = 0 then
begin
with CanvasList.LockList do
try
if Count >= CanvasListCacheSize then FreeDeviceContext;
FDeviceContext := FControl.GetDeviceContext(FWindowHandle); // 这里调用了之前说的GetDeviceContext
Add(Self);
finally
CanvasList.UnlockList;
end;
end;
Handle := FDeviceContext;
UpdateTextFlags;
end;
end;
SaveIndex := SaveDC(DC);
MoveWindowOrg(DC, Left, Top);
IntersectClipRect(DC, 0, 0, Width, Height);
Perform(WM_PAINT, DC, 0);
RestoreDC(DC, SaveIndex);
//只要把第一行
TRect rt( Left, Top, Left + Width, Top + Height );
//改成:
TRect rt = ClientRect;
function TControl.GetDeviceContext(var WindowHandle: HWnd): HDC;
begin
if Parent = nil then
raise EInvalidOperation.CreateFmt(SParentRequired, [Name]);
Result := Parent.GetDeviceContext(WindowHandle);
SetViewportOrgEx(Result, Left, Top, nil);
IntersectClipRect(Result, 0, 0, Width, Height);
end;