Text vertically aligned in a TwwDBGrid cell

Comments

1 comment

  • Roy Woll

    Hi Massimo, for some reason we were having notification problems with the zen desk system. Hopefully that is cleared up now. Now to answer your questions.

    I believe they should be aligned to top.  If you are trying to center the data, you could use the grid events to change the painting. For instance using both the OnAfterDrawCell and OnBeforeDrawCell you can change the text to vertically aligned. This code does it for the field 'first name'

    procedure TGridMemoApp.wwDBGrid1AfterDrawCell(Sender: TwwCustomDBGrid;

      DrawCellInfo: TwwCustomDrawGridCellInfo);

    var s: string;

        h, t: integer;

    begin

      if (drawcellinfo.Field<>nil) and (drawcellinfo.DataRow>=0) and

        (drawcellinfo.Field.FieldName = 'First Name') then

      begin

        s:= DrawCellInfo.Field.AsString;

        h:= Sender.Canvas.TextHeight(s);

        t:= DrawCellInfo.Rect.Top + (DrawCellInfo.Rect.Height - h) div 2;

        Sender.Canvas.TextRect(DrawCellInfo.Rect, DrawCellInfo.Rect.left, t, s);

      end;

    end;

     

    procedure TGridMemoApp.wwDBGrid1BeforeDrawCell(Sender: TwwCustomDBGrid;

      DrawCellInfo: TwwCustomDrawGridCellInfo);

    begin

      if (drawcellinfo.Field<>nil) and (drawcellinfo.DataRow>=0) and

        (drawcellinfo.Field.FieldName = 'First Name') then

      begin

        DrawCellInfo.DefaultDrawContents:= false;

      end;

    end;

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk