Board index » delphi » need help about this drawing problem

need help about this drawing problem


2005-10-27 11:28:15 PM
delphi253
hi,
i have a drawing problem here please help,
here is the simple code
============================================
procedure CustomDraw(DC: HDC; R: TRect);
var
Canvas: TCanvas;
begin
Canvas := TCanvas.Create;
try
Canvas.Handle := DC;
Canvas.Brush.Color := clSkyBlue;
Canvas.FillRect(R);
finally
Canvas.Handle := 0;
Canvas.Free;
end;
end;
{pb is paint box}
procedure TForm1.pbPaint(Sender: TObject);
var
R: TRect;
begin
R := pb.ClientRect;
CustomDraw(pb.Canvas.Handle, R);
pb.Canvas.TextOut(0, 0, 'Hello');
end;
================================================
the problem is 'Hello' text is not properly drawed according to the font.
i think the problem lies on CustomDraw procedure that i miss something
but i don't know what I am missing
thanks in advance
 
 

Re:need help about this drawing problem

In article <XXXX@XXXXX.COM>, Erick Hartanto writes:
Quote
============================================
procedure CustomDraw(DC: HDC; R: TRect);
var
Canvas: TCanvas;
begin
Canvas := TCanvas.Create;
try
SaveDC(DC);
Canvas.Handle := DC;
Canvas.Brush.Color := clSkyBlue;
Canvas.FillRect(R);
finally
Canvas.Handle := 0;
RestoreDC(DC, 0);
Canvas.Free;
end;
end;

{pb is paint box}
procedure TForm1.pbPaint(Sender: TObject);
var
R: TRect;
begin
R := pb.ClientRect;
CustomDraw(pb.Canvas.Handle, R);
Is there a particular reason why you are passing the canvas.handle instead
of the canvas itself?
pb.canvas.font := pb.font;
Quote
pb.Canvas.TextOut(0, 0, 'Hello');
end;
Peter Below (TeamB)
Use the newsgroup archives :
www.mers.com/searchsite.html
www.tamaracka.com/search.htm
groups.google.com
www.prolix.be
 

Re:need help about this drawing problem

thanks Peter, that is the code I am missing for :)
but the code should be to be working
OldDC := SaveDC(DC);
RestoreDC(DC, OldDC);
anyway thank you very much
hmm maybe the reason i pass the dc instead the canvas
is because in the customdraw method
i often change the brush mode and brush color etc
so i think better pass the handle then create the canvas
so the canvas color isn't affected after customdraw method