Einzelnen Beitrag anzeigen

Ginko

Registriert seit: 30. Aug 2008
208 Beiträge
 
FreePascal / Lazarus
 
#4

Re: InplaceEditor von Stringgrid zentrieren

  Alt 27. Dez 2009, 18:06
So ich habe es jetzt endlich gelöst hier meine Lösung:


Delphi-Quellcode:
unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids;

type
  TExtInplaceEdit = class(TInplaceEdit)
  protected
    procedure CreateParams(var Params: TCreateParams); override;
  end;

  TExtStringGrid = class(TStringGrid)
  protected
    function CreateEditor: TInplaceEdit; override;
  public
    constructor Create(AOwner: TComponent); override;
    procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
  end;


implementation


{ TExtInplaceEdit }
procedure TExtInplaceEdit.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.Style := Params.Style or LongWord(ES_Center); //Text des InplceEditors zentriert darstellen
end;

{ TExtStringGrid }
constructor TExtStringGrid.Create(AOwner: TComponent);
begin
  inherited;
  Parent := AOwner as TWinControl;
  DefaultColWidth := 75;
  DefaultRowHeight := 20;
  FixedCols := 0;
  FixedRows := 0;
  ColCount := 2;
  RowCount := 4;
  Width := 160;
  Height :=90;
  Options := Options + [goEditing];
  Selection := TGridRect(Rect(-1,-1,-1,-1));
end;

function TExtStringGrid.CreateEditor: TInplaceEdit;
begin
  Result := TExtInplaceEdit.Create(Self);
end;

procedure TExtStringGrid.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
var s: string;
begin
  s := Cells[ACol, ARow];
   //Text im Stringgrid zentriert darstellen
  DrawText(Canvas.Handle, PChar(s), Length(s), ARect, DT_SINGLELINE or DT_Center or DT_VCENTER);
end;

end.
  Mit Zitat antworten Zitat