StringGrid i OnDrawCell

0

Witam

Napisałem komponent (ubogi) na bazie Stringgrida umożliwiający operacje na położeniu tekstu wewnątrz komórek (Kod poniżej). Niestety po jego uruchomieniu i inicjacji, nie działa OnDrawCell. Hmm nie wiem co z faktem zrobić :). Pozdrawiam

unit NoveSGrid;

interface

uses
  WinProcs, SysUtils, Classes, Controls, Grids;

type
  TCellAlignment = (caTopLeft, caTopCenter, caTopRight, caMiddleLeft, caCenter, caMiddleRight, caBottomLeft, caBottomCenter, caBottomRight);

  TNoveSGrid = class(TStringGrid)
	private
  	FDefaultCellsAlignment  : TCellALignment;
  	procedure SetDefaultCellsAlignment(Value : TCellALignment);    
  	{ Private declarations }
	protected
  	procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
  	{ Protected declarations }
	public
  	constructor Create(AOwner : TComponent); override;
  	destructor Destroy; override;
  	{ Public declarations }
	published
  	property DefaultCellsAlignment : TCellALignment read FDefaultCellsAlignment write SetDefaultCellsAlignment;
    { Published declarations }
  end;

procedure Register;

implementation

//Procedury We-Wy
procedure Register;
	begin
  	RegisterComponents('Nove', [TNoveSGrid]);
	end;

constructor TNoveSGrid.Create(AOwner : TComponent);
	begin
  	inherited Create(AOwner);
  	FDefaultCellsAlignment:=caTopLeft;
	end;

destructor TNoveSGrid.Destroy;
	begin
  	inherited Destroy;
	end;
// --------------------------------------------------------------------------
procedure TNoveSGrid.SetDefaultCellsAlignment(Value : TCellALignment);
begin
  if Value<>FDefaultCellsAlignment then
  begin
    FDefaultCellsAlignment:=Value;
    Invalidate;
  end;
end;


// --------------------------------------------------------------------------

procedure TNoveSGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
          AState: TGridDrawState);
var AAlignment   : TCellAlignment;
    TheRect      : TRect;
    AFormat      : Longint;
    S            : string;
    //Hold         : Integer;
begin
  {Default alignment}
  AAlignment:=FDefaultCellsAlignment;
  {Call the event if assigned}
  if DefaultDrawing
  then
    begin
      AFormat:=DT_NOPREFIX+DT_SINGLELINE;
      case AAlignment of
        caTopCenter    : AFormat:=AFormat+DT_TOP+DT_CENTER;
        caTopRight     : AFormat:=AFormat+DT_TOP+DT_RIGHT;
        caMiddleLeft   : AFormat:=AFormat+DT_VCENTER+DT_LEFT;
        caCenter       : AFormat:=AFormat+DT_VCENTER+DT_CENTER;
        caMiddleRight  : AFormat:=AFormat+DT_VCENTER+DT_RIGHT;
        caBottomLeft   : AFormat:=AFormat+DT_BOTTOM+DT_LEFT;
        caBottomCenter : AFormat:=AFormat+DT_BOTTOM+DT_CENTER;
        caBottomRight  : AFormat:=AFormat+DT_BOTTOM+DT_RIGHT;
        else AFormat:=AFormat+DT_TOP+DT_LEFT;
      end;
      {Offsets adjustments}
      TheRect:=ARect;
      Canvas.FillRect(TheRect);
      TheRect.Top:=TheRect.Top+2;
      TheRect.Bottom:=TheRect.Bottom-2;
      TheRect.Left:=TheRect.Left+2;
      TheRect.Right:=TheRect.Right-2;
      S := Cells[ACol, ARow];
      DrawText(Canvas.Handle, PChar(S), Length(S), TheRect, AFormat);
      {	// _dopisano
      if Assigned(FOnDrawCell) then
  			begin
    			if UseRightToLeftAlignment then
    				begin
      				ARect.Left := ClientWidth - ARect.Left;
      				ARect.Right := ClientWidth - ARect.Right;
      				Hold := ARect.Left;
      				ARect.Left := ARect.Right;
      				ARect.Right := Hold;
      				ChangeGridOrientation(False);
    				end;
    				FOnDrawCell(Self, ACol, ARow, ARect, AState);
    				if UseRightToLeftAlignment then ChangeGridOrientation(True);
  			end;
        }// _dopisano
    end
  else inherited DrawCell(ACol, ARow, ARect, AState);

end;

end.
0

A czy StringGrid ma zaznaczone OwnerDraw na True ??

0

OwnerDraw jak OwnerDraw, ale DefaultDrawing dałbym na False :)

b

0

Witam

DefaultDrawing jest na true - aby nie stracić 3D itp,

OnOwnerDraw jest włączone :(, ale mam wrażenie że problem leży w dziedziczeniu z StringGrida:(

1 użytkowników online, w tym zalogowanych: 0, gości: 1