Link to home
Start Free TrialLog in
Avatar of skel
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
Avatar of erajoj
erajoj
Flag of Sweden image

Avatar of skel
skel

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
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.Canvas.Handle, Mode);
   ExtTextOut(StringGrid1.Canvas.Handle, xpos, Rect.Top + 5,
          ETO_CLIPPED or ETO_OPAQUE, @Rect,
          PChar(StringGrid1.Cells[Col, Row]),
          Length(StringGrid1.Cells[Col, Row]), nil);

end;

if you want to display characters in center vertically, you can change 'Rect.Top + 5' to a proper value.

Sakya
ASKER CERTIFIED SOLUTION
Avatar of sakya
sakya

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial