Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Überprüfungs Problem (https://www.delphipraxis.net/79684-ueberpruefungs-problem.html)

Specialradio 26. Okt 2006 14:00


Überprüfungs Problem
 
Hallo, Ich soll von einem anderen Azubi das Programm "Sudoku" weiter entwickeln.

nun bin ich ratlos, bei den sachen, die ich machen muss.
Wenn ich auf ein label(in der hauptform) klicke, muss überprüft werden, wo befinde ich mich (in welcher spalte und zeile)

wie könnte ich das rausbekommen ?

hier mein code:

MfG Mike

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  tmylabel = class (TLabel)
   procedure WMPaint(var Message : TMessage); message wm_Paint;
  end;
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
    lastclickedlabel: TMyLabel;
  public
    procedure Labelclick(Sender: TObject);
    procedure MouseM(Sender : TObject; Shift : TShiftState; x, y : Integer);
    procedure KleinLabelMouseDown(Sender: TObject; Button : TMouseButton; Shift : TShiftstate; x,y : Integer);
    procedure PanelMouseDown(Sender: TObject; Button : TMouseButton; Shift : TShiftstate; x,y : Integer);


    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Zahl,reihe1, reihe2,reihe3,reihe4,reihe5,reihe6,reihe7,reihe8,reihe9 : integer;



implementation

uses Unit2;

{$R *.DFM}
// Sudoku-Knacker.de FeldID: 29471


procedure TForm1.Labelclick(Sender: TObject);
var
 ZahlenPanel: TPanel;
 j, i, pg: integer;
 p : TPanel;
 l : TMyLabel;
begin
 Showmessage(IntToStr(TMyLabel(sender).Tag));


 with TLabel(Sender) do
 begin

  if assigned (focuscontrol) then focuscontrol.visible := true else
  begin
   p := TPanel.Create(Application);
   FocusControl := p;
   with p do
   begin
    parent := self;
    height := TLabel(Sender).height;
    width := TLabel(Sender).width;
    left  := TLabel(Sender).left;
    top   := Tlabel(Sender).top;
    OnMouseDown := PanelMouseDown;
   end;
   pg := Round(p.height -2);
   for j := 1 to 3 do
   begin
    for i := 1 to 3 do
    begin
     l := TMyLabel.Create(self);
     with l do
     begin
      Focuscontrol:= Pointer(Sender);
      parent  := p;
      autosize := false;
      height  := Round(p.height / 3);
      width   := height;
      left    := (j-1) * width ;
      top     := (i-1) * height;
      caption := IntToStr((i - 1) * 3 + j);
      Alignment:= tacenter;
      Canvas.Brush.Color := clBtnFace;
      OnMouseDown := kleinLabelMouseDown;
     end;
    end;
   end;
  end;
 end;
 Repaint;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
 s,
 i,           // Zeilenzähler
 j,
 k,          // Spaltenzähler
 lg,          // Labelgröße
 bg :Integer; // Boxgröße
 l : array [1..9 ,1..9 ] of TMyLabel;
 lb : TLabel;
begin

 lastclickedLabel:= nil;
 Zahl := 0;
 k := 0;
 ClientHeight := round(screen.height*0.8);
 ClientWidth := ClientHeight;
 lg := Round((ClientHeight-20)/9);
 ClientHeight := 9*lg+20;
 ClientWidth := ClientHeight;
  for i:=1 to 9 do
  begin
   for j:= 1 to 9 do
   begin
   l[i,j] :=TMyLabel.Create(Application) ;
     with l[i,j] do
     begin
       k := k+1;
       OnMouseMove := MouseM;
       Top := ((i-1)* lg)+13;
       Parent:= self;
       AutoSize := false;
       Font.Size := 12;
       Left := 10 + lg * (j-1) ;
       Height:= lg;
       Width:=lg;
       tag := k;
       canvas.font.Style := [fsbold];
       canvas.font.Size := 15;
       //Caption:= IntToStr(i)+','+(IntToStr(j));
       Alignment := tacenter;
       onclick := labelclick;
       Canvas.Brush.Color := clBtnFace;
     end;
    end;
  end;
  l[i,j] := TMyLabel.Create(nil);
  l[i,j].parent := self;
  //Beschriftungen;
  l[1,1].Caption := '6';
  l[1,2].Caption := '5';
  l[1,4].Caption := '1';
  l[1,5].Caption := '3';
  l[1,7].caption := '8';
  l[1,8].caption := '7';
  l[1,9].caption := '2';
  l[2,2].caption := '8';
  l[2,3].caption := '7';
  l[2,4].caption := '6';
  l[2,6].caption := '4';
  l[2,7].caption := '1';
  l[3,1].caption := '1';
  l[3,3].caption := '9';
  l[3,5].caption := '8';
  l[3,8].caption := '5';
  l[3,9].caption := '4';
  l[4,2].caption := '4';
  l[4,3].caption := '6';
  l[4,4].caption := '5';
  l[4,6].caption := '2';
  l[4,9].caption := '8';
  l[5,1].caption := '9';
  l[5,3].caption := '6';
  l[5,4].caption := '8';
  l[5,5].caption := '7';
  l[5,7].caption := '4';
  l[5,8].caption := '2';
  l[5,9].caption := '6';
  l[6,2].caption := '2';
  l[6,6].caption := '6';
  l[6,7].caption := '7';
  l[6,8].caption := '9';
  l[7,2].caption := '7';
  l[7,7].caption := '2';
  l[7,8].caption := '6';
  l[8,1].caption := '4';
  l[8,2].caption := '9';
  l[8,3].caption := '2';
  l[8,4].caption := '6';
  l[8,5].caption := '3';
  l[8,7].caption := '5';
  l[8,8].caption := '8';
  l[9,2].caption := '6';
  l[9,4].caption := '7';
  l[9,5].caption := '2';
  l[9,6].caption := '5';
  l[9,7].caption := '9';
  l[9,8].caption := '4';
  l[9,9].caption := '3';
  //Ende Beschriftungen
end;


procedure TForm1.FormPaint(Sender: TObject);
var i : integer;
 bg :Integer; // boxgröße
begin
 inherited;
 bg := Round((ClientHeight-20)/9)*3;
 for i := 1 to 2 do
 begin
  Canvas.MoveTo(10, bg*i+10);
  Canvas.LineTo(Clientwidth-10, bg*i+10);
  Canvas.MoveTo(bg*i+10, 10);
  Canvas.LineTo(bg*i+10, Clientheight-10);
 end;
end;

{ tmylabel }

procedure tmylabel.WMPaint(var Message: TMessage);
begin

 Canvas.TextOut((width shr 1) - (Canvas.TextWidth(Caption) shr 1), (height shr 1) - (Canvas.TextHeight(Caption) shr 1), caption);
 TForm(GetParentForm(self)).OnPaint(self);
end;


procedure TForm1.MouseM(Sender: TObject; Shift: TShiftState; x,
  y: Integer);
begin
 //Canvas.DrawFocusRect(TLabel(Sender).BoundsRect);
end;


procedure TForm1.Timer1Timer(Sender: TObject);
begin
 timer1.enabled := false;
 If Zahl = 1 then
 begin
 lastclickedlabel.Visible := not lastclickedlabel.visible;
 end else if Zahl > 1 then
 begin
  with lastclickedlabel do
  begin
   TLabel(Focuscontrol).Caption := Caption;
   TLabel(Focuscontrol).focuscontrol.visible := false;
   Zahl := 0;
  end;
 end;
 Zahl := 0;
 lastclickedlabel := nil;
end;

procedure TForm1.KleinLabelMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftstate; x, y: Integer);
var
 i,j,caption : Integer;
begin
//  for j := 1 to 9 do
// begin
//  for i := 1 to 9 do
//   caption := (i-1) * 9;
//  end;
// end;
If TMyLabel(Sender) = lastclickedlabel then
 begin
  inc(zahl);
 end else
 begin
  zahl := 1;
  Lastclickedlabel := TMyLabel(Sender);
 end;
 If not Timer1.Enabled then timer1.enabled := true;
end;

procedure TForm1.PanelMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftstate; x, y: Integer);
var
 Control : TControl;
 i: integer;
begin

 for i := 0 to TPanel(Sender).ControlCount-1 do
 begin
  with TPanel(Sender).Controls[i] do
  begin
   If ((x < left) or (x > Left+Width)) or ((y < top) or (y > Top+Height)) then else visible := true;

  end;
 end;
end;

end.


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:39 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz