List Info

Thread: RE: Working with ExtTextOut




RE: Working with ExtTextOut
country flaguser name
United States
2008-03-19 11:11:43

Hi David!

Thanks for the tip...However I can't get it to work...:-(

Can you suggest how I would incorporate Sender into my code?

Thanks in advance!

Tom Nesler

-----Original Message-----
From: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com [mailto: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com] On
Behalf Of David Smith
Sent: Wednesday, March 19, 2008 10:45 AM
To: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
Subject: RE: [delphi-en] Working with ExtTextOut

You should use Sender instead of StringGrid1. That's what it's for.

"Nesler, Thomas J" < tnesler%40amfam.com">tnesleramfam.com> wrote:
Hi Rob!

Your observation combined with Theo's code cleanup fixed the problem.

Here is the final code for those who may need to do this in the future:

// *** This procedure Centers all cells in the grid ****

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow:
Integer;
Rect: TRect; State: TGridDrawState);
var
Text : string;
Begin
Text := StringGrid1.Cells[Acol,ARow];
ExtTextOut(StringGrid1.Canvas.Handle,
Rect.Left + (Rect.Right - Rect.Left -
StringGrid1.Canvas.TextWidth(Text)) div 2,
Rect.Top + 2,
ETO_OPAQUE or ETO_CLIPPED,
Rect,
PChar(Text),
Length(Text),
nil);
end;

//************** End of Code ***********

Thanks for your input, Rob

Tom Nesler
Live long!... Code Well!... and Prosper!... V

-----Original Message-----
From: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com [mailto: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com] On
Behalf Of Rob Kennedy
Sent: Tuesday, March 18, 2008 8:07 PM
To: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
Subject: Re: [delphi-en] Working with ExtTextOut

....
> ExtTextOut(Handle,
> // HDC
> Rect.Left + (Rect.Right - Rect.Left -
> TextWidth(Text)) div 2, // X Position
> Top + DY,

Do you mean Rect.Top?





---------------------------------
Never miss a thing. Make Yahoo your homepage.

[Non-text portions of this message have been removed]

------------------------------------

-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: delphi-en-unsubscribe%40yahoogroups.comYahoo">delphi-en-unsubscribeyahoogroups.comYahoo! Groups Links

__._,_.___
.

__,_._,___
Re: Working with ExtTextOut
country flaguser name
United States
2008-03-19 12:23:50


Sender is the component calling your event handler. For example it's
not uncommon to use the same method for more than one button click
event when they perform very similar tasks. You then write code like:

if (Sender as TButton).Name = 'btnPrint' then
begin
// do stuff
end
else (Sender as TButton).Name = 'btnTestPrint' then
begin
// do slightly different stuff
end;
// do stuff common to both print buttons

You need to cast the Sender object to whatever type you expect it to
be because it is of type TObject which doesn't have properties like
Canvas or Handle. So if you're using Sender instead of StringGrid1
you'll have some code like: (Sender as TStringGrid).Canvas.Handle

Hope this helps,
Dave.

Dave Murray
Glasgow, UK

--- In delphi-en%40yahoogroups.com">delphi-enyahoogroups.com, "Nesler, Thomas J" <tnesler...> wrote:
&gt;
> Hi David!
&gt;
> Thanks for the tip...However I can't get it to work...:-(
>
> Can you suggest how I would incorporate Sender into my code?
&gt;
> Thanks in advance!
>
> Tom Nesler
&gt;
>
> -----Original Message-----
> From: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com [mailto: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com] On
> Behalf Of David Smith
&gt; Sent: Wednesday, March 19, 2008 10:45 AM
> To: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
&gt; Subject: RE: [delphi-en] Working with ExtTextOut
>
>
> You should use Sender instead of StringGrid1. That's what it's for.
>;
> "Nesler, Thomas J" <tnesler...> wrote:
&gt; Hi Rob!
>;
> Your observation combined with Theo's code cleanup fixed the problem.
>
> Here is the final code for those who may need to do this in the future:
>
> // *** This procedure Centers all cells in the grid ****
>;
> procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow:
&gt; Integer;
> Rect: TRect; State: TGridDrawState);
&gt; var
> Text : string;
> Begin
&gt; Text := StringGrid1.Cells[Acol,ARow];
> ExtTextOut(StringGrid1.Canvas.Handle,
&gt; Rect.Left + (Rect.Right - Rect.Left -
> StringGrid1.Canvas.TextWidth(Text)) div 2,
> Rect.Top + 2,
> ETO_OPAQUE or ETO_CLIPPED,
> Rect,
&gt; PChar(Text),
> Length(Text),
> nil);
&gt; end;
>;
> //************** End of Code ***********
>
> Thanks for your input, Rob
>
> Tom Nesler
&gt; Live long!... Code Well!... and Prosper!... V
>
> -----Original Message-----
> From: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com [mailto: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com] On
> Behalf Of Rob Kennedy
> Sent: Tuesday, March 18, 2008 8:07 PM
> To: delphi-en%40yahoogroups.com">delphi-enyahoogroups.com
&gt; Subject: Re: [delphi-en] Working with ExtTextOut
>
> ....
>; > ExtTextOut(Handle,
> > // HDC
> > Rect.Left + (Rect.Right - Rect.Left -
> > TextWidth(Text)) div 2, // X Position
> > Top + DY,
>
> Do you mean Rect.Top?
>
>
>
>
>
>
> ---------------------------------
> Never miss a thing. Make Yahoo your homepage.
>
> [Non-text portions of this message have been removed]
>
>
> ------------------------------------
&gt;
> -----------------------------------------------------
> Home page: http://groups.yahoo.com/group/delphi-en/
> To unsubscribe: delphi-en-unsubscribe...! Groups Links
&gt;

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )