Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi InplaceEditor von Stringgrid zentrieren (https://www.delphipraxis.net/145100-inplaceeditor-von-stringgrid-zentrieren.html)

Ginko 23. Dez 2009 17:05


InplaceEditor von Stringgrid zentrieren
 
Hallo gibt es eine Möglichkeit den InplaceEditor bei jeder eingabe in eine Stringgrid-Zelle zu zentrieren?

Ginko 25. Dez 2009 12:18

Re: InplaceEditor von Stringgrid zentrieren
 
Ist es nicht irgendwie möglich mit der Funktion

Delphi-Quellcode:
function CreateEditor: TInplaceEdit; override;
bei der Erstellung des InplaceEditor das oben beschriebene zu erreichen?
In der Art zB:

Delphi-Quellcode:
function TEigenesStringgrid.CreateEditor;
var CustomInplace: TInplaceEdit;
begin
  CustomInplace := TInplaceEdit.Create(self);
  CustomInplace.Left := 20;
  Result := CustomInplace;
end;
Was aber leider nicht klappt...

Ginko 27. Dez 2009 16:17

Re: InplaceEditor von Stringgrid zentrieren
 
Crossling zu Delphi-Forum

Ginko 27. Dez 2009 18:06

Re: InplaceEditor von Stringgrid zentrieren
 
So ich habe es jetzt endlich gelöst hier meine Lösung: :bounce2:


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.


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:18 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz