 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Erick Hartanto Guest
|
Posted: Thu Oct 27, 2005 3:28 pm Post subject: need help about this drawing problem |
|
|
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'm missing
thanks in advance
|
|
| Back to top |
|
 |
Peter Below (TeamB) Guest
|
Posted: Thu Oct 27, 2005 6:23 pm Post subject: Re: need help about this drawing problem |
|
|
In article <4360f15c (AT) newsgroups (DOT) borland.com>, Erick Hartanto wrote:
| 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 :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
|
|
| Back to top |
|
 |
Erick Hartanto Guest
|
Posted: Fri Oct 28, 2005 7:31 am Post subject: Re: need help about this drawing problem |
|
|
thanks Peter, that's the code i'm 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
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|