skel
asked on
How to align text in a String Grid Control
Hi!! I need to align the text of the row in a grid control in the middle of the row... how can I accomplish that?
Thanks in advance
Jaime
Thanks in advance
Jaime
ASKER
Thanks.. I've downloaded one of those controls. but I forgot to tell you that I need to align the text in the middle of the cell, but vertically. That control only aligns it hortizontally.
Can you explain me how can I use ownerdraw? Other fact I have observed with that control in torry site, that is visible slower that the StringGrid coming with Delphi 3. This is bad for my program, so I need to try another solution.
Thanks in advance
Jaime
Can you explain me how can I use ownerdraw? Other fact I have observed with that control in torry site, that is visible slower that the StringGrid coming with Delphi 3. This is bad for my program, so I need to try another solution.
Thanks in advance
Jaime
Hello.
this is a example.
--------------------
procedure TForm1.StringGrid1DrawCell (Sender: TObject; Col, Row: Integer;
Rect: TRect; State: TGridDrawState);
var
xpos,
Mode: Integer;
begin
if Col = 1 then begin //right side
Mode := DT_RIGHT or TA_TOP;
xpos := Rect.Right - 2;
end
else if Col = 2 then begin //left side
Mode := DT_LEFT or TA_TOP;
xpos := Rect.Left + 2;
end
else begin //middle
Mode := TA_CENTER or TA_TOP;
xpos := (Rect.Left + Rect.Right) div 2;
end;
SetTextAlign(StringGrid1.C anvas.Hand le, Mode);
ExtTextOut(StringGrid1.Can vas.Handle , xpos, Rect.Top + 5,
ETO_CLIPPED or ETO_OPAQUE, @Rect,
PChar(StringGrid1.Cells[Co l, Row]),
Length(StringGrid1.Cells[C ol, Row]), nil);
end;
if you want to display characters in center vertically, you can change 'Rect.Top + 5' to a proper value.
Sakya
this is a example.
--------------------
procedure TForm1.StringGrid1DrawCell
Rect: TRect; State: TGridDrawState);
var
xpos,
Mode: Integer;
begin
if Col = 1 then begin //right side
Mode := DT_RIGHT or TA_TOP;
xpos := Rect.Right - 2;
end
else if Col = 2 then begin //left side
Mode := DT_LEFT or TA_TOP;
xpos := Rect.Left + 2;
end
else begin //middle
Mode := TA_CENTER or TA_TOP;
xpos := (Rect.Left + Rect.Right) div 2;
end;
SetTextAlign(StringGrid1.C
ExtTextOut(StringGrid1.Can
ETO_CLIPPED or ETO_OPAQUE, @Rect,
PChar(StringGrid1.Cells[Co
Length(StringGrid1.Cells[C
end;
if you want to display characters in center vertically, you can change 'Rect.Top + 5' to a proper value.
Sakya
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Torry (http://www.torry.ru/):
http://www.torry.ru/vcl/grids/fadvgrid.zip
http://www.torry.ru/vcl/grids/hyperd3.zip
http://www.torry.ru/vcl/grids/aligrid.zip
http://www.torry.ru/vcl/grids/xl.zip
http://www.torry.ru/vcl/grids/cologrid.zip
http://www.torry.ru/vcl/grids/keoegrid.zip
DSP (http://sunsite.icm.edu.pl/delphi/)
Search for "grid" or "stringgrid"
/// John