读书人

*关于格子的有关问题*

发布时间: 2012-03-29 12:53:13 作者: rapoo

**********关于格子的问题********
我想做一个 6*11的 格子,同时有3盏灯(红色,绿色,黄色),当我按下键盘的“1”键时,格子[0,0] 显示红色灯,按下“2”键时格子[0,1] 显示绿色灯,按下“3”键时格子[0,2] 显示黄色灯,再按下“2”键时格子[0,3] 显示绿色灯,依次类推。。。。。当排满后就从新从格子[0,0]开始
请问DELPHI用什么控件能实现??希望能提供程序代码!!!谢谢!!!

[解决办法]
基础控件就可以做
[解决办法]
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Panel1: TPanel;
procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
Grids: array[0..10,0..5] of TLabel;
CurrPoint: TPoint;
Created: Boolean;
procedure UpdatePoint;
procedure CreateGrid;
public
{ 公共成员(变量、函数)声明 }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.UpdatePoint;
begin
if CurrPoint.x > = 5 then
begin
if CurrPoint.y > = 10 then Exit;
CurrPoint.x := 0;
Inc(CurrPoint.y);
end
else
Inc(CurrPoint.x);
end;

procedure TForm1.CreateGrid;
var
I, J, FLeft, FTop, FWidth, FHeight : Integer;
begin
if Created then
begin
for I := 0 to 10 do
for J := 0 to 5 do
Grids[I,J].Color := clWhite;
CurrPoint.x := 0;
CurrPoint.y := 0;
Exit;
end;

Created := True;
FLeft := 5;
FTop := 5;
FWidth := (Panel1.Width - 5*6 - FLeft) div 6;
FHeight := (Panel1.Height - 5*11 - FTop) div 11;
for I := 0 to 10 do
begin
for J := 0 to 5 do
begin
Grids[I,J] := TLabel.Create(Self);
with Grids[I,J] do
begin
AutoSize := False;
Caption := EmptyStr;
Left := FLeft;
Top := FTop;
Width := FWidth;
Height := FHeight;
Color := clWhite;
Parent := Panel1;
end;
FLeft := FLeft + FWidth + 5;
end;
FTop := FTop + FHeight + 5;
FLeft := 5;
end;
FillChar(CurrPoint,SizeOf(CurrPoint),0);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
CreateGrid;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if Not Created then CreateGrid;
Grids[CurrPoint.y,CurrPoint.x].Color := clRed;
UpdatePoint;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if Not Created then CreateGrid;
Grids[CurrPoint.y,CurrPoint.x].Color := clGreen;
UpdatePoint;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if Not Created then CreateGrid;
Grids[CurrPoint.y,CurrPoint.x].Color := clYellow;
UpdatePoint;
end;

end.
[解决办法]
用TShape
[解决办法]
可以用动态创建的Panel数组来实现。
[解决办法]
好久不来了,学习一下

读书人网 >.NET

热点推荐