Új hozzászólás Aktív témák

  • Yodafon

    senior tag

    Köszi szépen de már megoldódott.

    Én is ezen a nyomon indultam el, és ez jött ki belőle:

    unit Unit1;

    interface

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

    type
    TForm1 = class(TForm)

    StringGrid1: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
    var CanSelect: Boolean);

    procedure mezoSelectCell(Sender: TObject; ACol, ARow: Integer;
    var CanSelect: Boolean);

    procedure mezoDrawCell(Sender: TObject; ACol, ARow: Integer;
    Rect: TRect; State: TGridDrawState);



    private
    { Private declarations }
    public
    k:string[2];
    kord:record
    osz,sor:integer;
    end;
    mezo:array[1..9] of TStringGrid;
    { Public declarations }
    end;

    var
    Form1: TForm1;
    j:integer;
    implementation

    {$R *.dfm}


    procedure TForm1.FormCreate(Sender: TObject);
    var i:integer;
    begin
    for i:=1 to 9 do
    begin
    mezo[i]:=TStringGrid.create(form1);
    mezo[i].parent:=form1;
    end;


    mezo[1].Top:=20;
    mezo[1].Left:=50;
    mezo[1].FixedCols:=0;
    mezo[1].FixedRows:=0;
    mezo[1].ColCount:=3;
    mezo[1].RowCount:=3;
    mezo[1].DefaultColWidth:=20;
    mezo[1].DefaultRowHeight:=20;
    mezo[1].Ctl3D:=false;
    mezo[1].Width:=64;
    mezo[1].Height:=64;
    mezo[1].ScrollBars:=ssNone;
    mezo[1].tag:=1;


    mezo[2].Top:=20;
    mezo[2].Left:=120;
    mezo[2].FixedCols:=0;
    mezo[2].FixedRows:=0;
    mezo[2].ColCount:=3;
    mezo[2].RowCount:=3;
    mezo[2].DefaultColWidth:=20;
    mezo[2].DefaultRowHeight:=20;
    mezo[2].Ctl3D:=false;
    mezo[2].Width:=64;
    mezo[2].Height:=64;
    mezo[2].ScrollBars:=ssNone;
    mezo[2].Tag:=2;

    mezo[3].Top:=20;
    mezo[3].Left:=190;
    mezo[3].FixedCols:=0;
    mezo[3].FixedRows:=0;
    mezo[3].ColCount:=3;
    mezo[3].RowCount:=3;
    mezo[3].DefaultColWidth:=20;
    mezo[3].DefaultRowHeight:=20;
    mezo[3].Ctl3D:=false;
    mezo[3].Width:=64;
    mezo[3].Height:=64;
    mezo[3].ScrollBars:=ssNone;
    mezo[3].Tag:=3;


    mezo[4].Top:=90;
    mezo[4].Left:=50;
    mezo[4].FixedCols:=0;
    mezo[4].FixedRows:=0;
    mezo[4].ColCount:=3;
    mezo[4].RowCount:=3;
    mezo[4].DefaultColWidth:=20;
    mezo[4].DefaultRowHeight:=20;
    mezo[4].Ctl3D:=false;
    mezo[4].Width:=64;
    mezo[4].Height:=64;
    mezo[4].ScrollBars:=ssNone;
    mezo[4].tag:=4;


    mezo[5].Top:=90;
    mezo[5].Left:=120;
    mezo[5].FixedCols:=0;
    mezo[5].FixedRows:=0;
    mezo[5].ColCount:=3;
    mezo[5].RowCount:=3;
    mezo[5].DefaultColWidth:=20;
    mezo[5].DefaultRowHeight:=20;
    mezo[5].Ctl3D:=false;
    mezo[5].Width:=64;
    mezo[5].Height:=64;
    mezo[5].ScrollBars:=ssNone;
    mezo[5].Tag:=5;


    mezo[6].Top:=90;
    mezo[6].Left:=190;
    mezo[6].FixedCols:=0;
    mezo[6].FixedRows:=0;
    mezo[6].ColCount:=3;
    mezo[6].RowCount:=3;
    mezo[6].DefaultColWidth:=20;
    mezo[6].DefaultRowHeight:=20;
    mezo[6].Ctl3D:=false;
    mezo[6].Width:=64;
    mezo[6].Height:=64;
    mezo[6].ScrollBars:=ssNone;
    mezo[6].Tag:=6;


    mezo[7].Top:=160;
    mezo[7].Left:=50;
    mezo[7].FixedCols:=0;
    mezo[7].FixedRows:=0;
    mezo[7].ColCount:=3;
    mezo[7].RowCount:=3;
    mezo[7].DefaultColWidth:=20;
    mezo[7].DefaultRowHeight:=20;
    mezo[7].Ctl3D:=false;
    mezo[7].Width:=64;
    mezo[7].Height:=64;
    mezo[7].ScrollBars:=ssNone;
    mezo[7].Tag:=7;


    mezo[8].Top:=160;
    mezo[8].Left:=120;
    mezo[8].FixedCols:=0;
    mezo[8].FixedRows:=0;
    mezo[8].ColCount:=3;
    mezo[8].RowCount:=3;
    mezo[8].DefaultColWidth:=20;
    mezo[8].DefaultRowHeight:=20;
    mezo[8].Ctl3D:=false;
    mezo[8].Width:=64;
    mezo[8].Height:=64;
    mezo[8].ScrollBars:=ssNone;
    mezo[8].tag:=8;


    mezo[9].Top:=160;
    mezo[9].Left:=190;
    mezo[9].FixedCols:=0;
    mezo[9].FixedRows:=0;
    mezo[9].ColCount:=3;
    mezo[9].RowCount:=3;
    mezo[9].DefaultColWidth:=20;
    mezo[9].DefaultRowHeight:=20;
    mezo[9].Ctl3D:=false;
    mezo[9].Width:=64;
    mezo[9].Height:=64;
    mezo[9].ScrollBars:=ssNone;
    mezo[9].tag:=9;

    for i:=0 to 10 do
    StringGrid1.Cells[i,0]:=inttostr(i+1);

    mezo[1].ONSelectCell:=mezoSelectCell;
    mezo[2].ONSelectCell:=mezoSelectCell;
    mezo[3].ONSelectCell:=mezoSelectCell;
    mezo[4].ONSelectCell:=mezoSelectCell;
    mezo[5].ONSelectCell:=mezoSelectCell;
    mezo[6].ONSelectCell:=mezoSelectCell;
    mezo[7].ONSelectCell:=mezoSelectCell;
    mezo[8].ONSelectCell:=mezoSelectCell;
    mezo[9].ONSelectCell:=mezoSelectCell;

    mezo[1].ONDrawCell:=mezoDrawCell;
    mezo[2].ONDrawCell:=mezoDrawCell;
    mezo[3].ONDrawCell:=mezoDrawCell;
    mezo[4].ONDrawCell:=mezoDrawCell;
    mezo[5].ONDrawCell:=mezoDrawCell;
    mezo[6].ONDrawCell:=mezoDrawCell;
    mezo[7].ONDrawCell:=mezoDrawCell;
    mezo[8].ONDrawCell:=mezoDrawCell;
    mezo[9].ONDrawCell:=mezoDrawCell;
    StringGrid1.OnDrawCell:=mezoDrawCell;
    end;


    procedure TForm1.mezoSelectCell(Sender: TObject; ACol,
    ARow: Integer; var CanSelect: Boolean);
    begin

    StringGrid1.Visible:=true;
    kord.osz:=ACol;
    kord.sor:=Arow;
    case (Sender as TStringGrid).Tag of
    1:begin j:=1;mezo[1].Cells[kord.osz,kord.sor]:=k; end;
    2:begin j:=2;mezo[2].Cells[kord.osz,kord.sor]:=k; end;
    3:begin j:=3;mezo[3].Cells[kord.osz,kord.sor]:=k; end;
    4:begin j:=4;mezo[4].Cells[kord.osz,kord.sor]:=k; end;
    5:begin j:=5;mezo[5].Cells[kord.osz,kord.sor]:=k; end;
    6:begin j:=6;mezo[6].Cells[kord.osz,kord.sor]:=k; end;
    7:begin j:=7;mezo[7].Cells[kord.osz,kord.sor]:=k; end;
    8:begin j:=8;mezo[8].Cells[kord.osz,kord.sor]:=k; end;
    9:begin j:=9;mezo[9].Cells[kord.osz,kord.sor]:=k; end;
    end;
    end;

    procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
    ARow: Integer; var CanSelect: Boolean);
    begin
    mezo[j].Cells[kord.osz,kord.sor]:=StringGrid1.Cells[ACol,Arow];
    StringGrid1.Visible:=false;
    end;



    procedure TForm1.mezoDrawCell(Sender: TObject; ACol, ARow: Integer;
    Rect: TRect; State: TGridDrawState);
    begin
    with (Sender as TStringGrid).Canvas do
    begin
    Font.Color := clBlack;
    { if the cell is selected, or focused then we use the highlight color for the cell }
    if (gdSelected in State) or (gdFocused in State) then
    brush.Color := clwhite
    { if the cell is FIXED then we just use the color of the face of a button }
    else if (gdFixed in State) then
    brush.Color := clwhite
    { else it is just the window color - or any other color you want }
    else
    Brush.Color := clwhite;
    FillRect(Rect);

    if (gdSelected in State) or (gdFocused in State) then
    Font.Color := clBlack;
    { Draw the text in the cell - you could draw anything in there }
    TextRect(Rect, Rect.Left+2, Rect.Top+2, (Sender as TStringGrid).Cells[ACol, ARow]);
    end;
    end;

    end.

    Ez annyit csinál hogy 9 db 3x3 -as cellát készít és ha az egyik cellába belekattintok akkor felugrik egy másik mező, ahol ki lehet választani a bele kerülő számot. Igazából Sudokut akarok csinálni anyámnak mert most nagyon rákattant. :DDD

    De azért köszi szépen mindkettőtöknek, hogy segítettetek ilyen amatőrnek mint én.
    :R

    I'm gangsta!

Új hozzászólás Aktív témák