1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64:
| 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
procedure TExtInplaceEdit.CreateParams(var Params: TCreateParams); begin inherited; Params.Style := Params.Style or LongWord(ES_Center); end;
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]; DrawText(Canvas.Handle, PChar(s), Length(s), ARect, DT_SINGLELINE or DT_Center or DT_VCENTER); end;
end. |