...
private
{ Private-Deklarationen }
public
procedure Clicks(i: integer);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
xx, yy: integer;
isdown: boolean = false;
procedure TForm1.FormCreate(Sender: TObject);
begin
with STringGrid1 do begin
DefaultDrawing := false;
// --- nur zum Testen ---
cells[1, 0] := 'Test';
cells[1, 1] := '1';
cells[1, 2] := '2';
cells[1, 3] := '3';
// ----------------------
end;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure fill(F: TColor);
begin
with TStringgrid(Sender).canvas do begin
brush.color := F;
fillrect(Rect);
end;
end;
procedure versatz(i: integer);
begin
inc(Rect.left, i);
inc(Rect.top, i);
end;
procedure rand1(b: boolean);
begin
with TStringgrid(Sender).canvas do begin
if b then Pen.color := clbtnshadow
else Pen.color := clbtnhighlight;
moveto(rect.left, Rect.bottom - 1);
lineto(rect.left, rect.top);
lineto(rect.right, rect.top);
end;
end;
procedure rand2(b: boolean);
begin
with TStringgrid(Sender).canvas do begin
if b then exit;
Pen.color := clbtnshadow;
moveto(rect.left + 1, Rect.bottom - 1);
lineto(rect.right - 1, Rect.bottom - 1);
lineto(rect.right - 1, rect.top);
end;
end;
begin
with TStringgrid(Sender), canvas do begin
if (Acol < Fixedcols) or (ARow < Fixedrows) then begin
fill(clbtnface);
if (xx > 0) and (yy = 0) and (Arow = yy) and (Acol = xx)
then begin
rand1(isdown);
rand2(isdown);
Versatz(2 + ord(isdown));
end else begin
rand1(false);
rand2(false);
Versatz(2);
end;
end else begin
fill(clWindow);
if gdFocused in State then drawfocusrect(Rect);
Versatz(2);
end;
font.color := clWindowText;
drawtext(handle, PChar(cells[acol, arow]), -1, Rect, dt_singleline);
end;
end;
procedure TForm1.Clicks(i: integer);
begin
// machwas, z.B.:
showmessage('Spalte ' + inttostr(i) + ' wurde angeklickt');
end;
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
isdown := true;
with TStringgrid(Sender) do begin
mousetocell(x, y, xx, yy);
refresh;
end;
end;
procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
isdown := false;
TStringgrid(Sender).refresh;
if (xx > 0) and (yy = 0) then Clicks(xx);
end;