How Can I do it ?
Thanks
Alejandro
--
Alejandro Castro Perez
COMPUTACION ALFRA SC
Cerro del Fortin 116-101
Col. Campestre Churubusco
04200 México, D.F.
Tel: 55 44 6014 y 55 44 3251
Lada sin Costo: 01 800 849 77 59
www.calfra.com.mx
In your DrawCell event:
var
X: Integer;
begin
with Sender as TStringGrid do
begin
SetTextAlign(Canvas.Handle, TA_RIGHT);
X := (Rect.Left+Rect.Right) div 2;
Canvas.TextRect(Rect, X, Rect.Top+2, Cells[ACol,
ARow]);
end;
end;
"Alejandro Castro" <cal...@mail.internet.com.mx> wrote in message
news:3ad60e0f_2@dnews...
Use the DrawText win32 API function. It has a parameter for alignment.
procedure TForm1.FormCreate(Sender: TObject);
var
c, r: integer;
begin
StringGrid1.ColCount := 3;
for r := 0 to StringGrid1.RowCount - 1 do
for c := 0 to StringGrid1.ColCount - 1 do
StringGrid1.Cells[c,r] := IntToStr(r)+':'+IntToStr(c);
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow:
Integer;
Rect: TRect; State: TGridDrawState);
var
Fmt: integer;
begin
StringGrid1.Canvas.FillRect(Rect);
{set alignment}
case ACol of
0: Fmt := DT_SINGLELINE or DT_VCENTER or DT_LEFT;
1: Fmt := DT_SINGLELINE or DT_VCENTER or DT_CENTER;
2: Fmt := DT_SINGLELINE or DT_VCENTER or DT_RIGHT;
end;
{shrink the rect in 2 pixels so the text is not on the grid line}
InflateRect(Rect, -2, 0);
DrawText(StringGrid1.Canvas.Handle,
PChar(StringGrid1.Cells[ACol,ARow]),
-1,
Rect,
Fmt);
end;
Visit http://www.govst.edu/users/gsmpati/delphi for a fancier example.
Is there a problem with TSTRINGGRID ?
When I call the onDrawCell event I receive allways the same col and row,
sometimes the content of cells[col,row] is empty, etc.. The event is
impredectible
Why? am I missing something ?
Thanks again
Alejandro
Alejandro Castro <cal...@mail.internet.com.mx> escribió en el mensaje de
noticias 3ad60e0f_2@dnews...
HTH
tom
Alejandro Castro <cal...@mail.internet.com.mx> schrieb in im Newsbeitrag:
3ad60e0f_2@dnews...
No.
> When I call the onDrawCell event I receive allways the same col and row,
> sometimes the content of cells[col,row] is empty, etc.. The event is
> impredectible
> Why? am I missing something ?
Perhaps you are thrown into a curve by the fact that the two parameters of
the event that pass in the col and row of the cell to draw are called Col
and Row, the same names used for the Col and Row *property* of the
stringgrid. So if you use a With construct inside the handler like
with sender as TStringgrid do begin
S:= Cells[ col, row ];
you will refer to the grid properties, not to the parameters of the event
handler! This has been fixed in later Delphi versions by renaming the
parameters aCol and aRow, to resolve the conflict. In older Delphi versions
you have to rename the parameters yourself, or copy the parameters to local
variables with nonconflicting names.
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.
I changed the name of the parameters Row and Col and works !!! and the code
is very simple (joining the code of everybody)
with (Sender as TStringGrid) do begin
Canvas.FillRect(Rect);
SetTextAlign(Canvas.Handle,TA_RIGHT);
Canvas.TextOut(Rect.Right-2,Rect.Top+1,Cells[aCol,aRow]);
end;
But now I have a question, I tried to find the TA_RIGHT and SETTEXTALIGN on
everywhere on the help files but I cant find them , where are they?
Thanks again
Alejandro
Peter Below (TeamB) <10011...@compuXXserve.com> escribió en el mensaje de
noticias VA.00006db...@antispam.compuserve.com...
"Alejandro Castro" <cal...@mail.internet.com.mx> wrote > But now I have a
You have to look in win32.hlp, the Windows API helpfile. If you just place the
caret onto the word to find in the editor and hit F1 it should take you to
that helpfile, if it has been installed properly. As far as i remember the API
helpfiles are an optional install item but included in the standard
installation.