Einzelnen Beitrag anzeigen

Serdradox

Registriert seit: 26. Sep 2009
1 Beiträge
 
#1

StringGrid Image [Mehrfach Zuweisen]

  Alt 26. Sep 2009, 20:38
Mein Problem ist, wie im Titel schon angedeutet, dass ich ein Image welches sich in einem StringGrid befindet "mehrfach" zuweisen möchte.
Zum Verständniss:
Es soll ein einfaches "Lotto"-Programm werden bei dem man seine Lottozahlen eintragen kann.

Komplett
Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    strgrdLottozahlen: TStringGrid;
    procedure strgrdLottozahlenDrawCell(Sender: TObject; ACol,
      ARow: Integer; Rect: TRect; State: TGridDrawState);
    procedure FormCreate(Sender: TObject);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  BitmapFeld,BitmapKreuz: TBitmap;
implementation

{$R *.dfm}

{Anfang: Funktion die überprüft ob eine "bestimmte" Spalte ausgewählt ist}
function IsCellSelected(StringGrid: TStringGrid; X, Y: Longint): Boolean;
begin
  Result := False;
  try
    if (X >= StringGrid.Selection.Left) and (X <= StringGrid.Selection.Right) and
      (Y >= StringGrid.Selection.Top) and (Y <= StringGrid.Selection.Bottom) then
      Result := True;
  except
  end;
end;
{Ende: Funktion die überprüft ob eine "bestimmte" Spalte ausgewählt ist}

procedure TForm1.strgrdLottozahlenDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var
{Normale-Variablen}
i,j,n,m:Integer;
begin
BitmapFeld := TBitmap.Create;
BitmapFeld.LoadFromFile('Bilder/LottoFeld.bmp');
BitmapFeld.TransparentColor := clWhite;
BitmapFeld.Transparent := True;

BitmapKreuz := TBitmap.Create;
BitmapKreuz.LoadFromFile('Bilder/LottoKreuz.bmp');
BitmapKreuz.TransparentColor := clWhite;
BitmapKreuz.Transparent := True;

for n:= 1 to 7 do
for m:= 1 to 7 do
begin
If IsCellSelected(strgrdLottozahlen,n,m) = True
then
strgrdLottozahlen.Canvas.StretchDraw(strgrdLottozahlen.CellRect(n,m),BitmapKreuz);
end;

for i := 1 to 7 do
for j := 1 to 7 do
begin
strgrdLottozahlen.Canvas.StretchDraw(strgrdLottozahlen.CellRect(i,j),BitmapFeld);
end;
end;


procedure TForm1.FormCreate(Sender: TObject);
var
x,y,z:Integer;
begin
z:=0 ;

for x := 1 to 7 do
for y := 1 to 7 do
begin
z:= z+1;
strgrdLottozahlen.Cells[y,x] := IntToStr(z);
end;

end;
end.
Das Grundproblem liegt in diesem Codebereich:
Delphi-Quellcode:
for n:= 1 to 7 do
for m:= 1 to 7 do
begin
If IsCellSelected(strgrdLottozahlen,n,m) = True
then
strgrdLottozahlen.Canvas.StretchDraw(strgrdLottozahlen.CellRect(n,m),BitmapKreuz);
end;
Da es nur das Kreuz setzt, wenn man die Spalte ausgewählt hat. Sobald man eine andere Spalte anklickt verschwindet das vorherige Kreuz [was nach dem Code Aufbau auch verständlich ist]. Mir würde schon ein "Ansatz" genügen, da ich ja gerne selbst das Projekt zur Vollendung bringen möchte.

Frage: Wie kann ich mehrere StringGrid Spalten auswählen, in denen dann auch die Kreuze [Lotto 6 aus 49] angezeigt bekommt.

MfG
Serdradox
  Mit Zitat antworten Zitat