unit USafeCard;
{$R 'Card.res' 'Card.rc'}
interface
uses
Windows, SysUtils, Classes, Forms,Dialogs,Graphics,Clipbrd,
StdCtrls, ExtCtrls, Buttons, Controls;
type
TForm8 = class(TForm)
GroupBox1: TGroupBox;
Image1: TImage;
BitBtn1: TBitBtn;
Button1: TButton;
Button2: TButton;
Shape1: TShape;
Label1: TLabel;
Label2: TLabel;
Panel1: TPanel;
Timer1: TTimer;
GroupBox2: TGroupBox;
Edit1: TEdit;
Button3: TButton;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn1MouseEnter(Sender: TObject);
procedure BitBtn1MouseLeave(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Shape1MouseEnter(Sender: TObject);
procedure Shape1MouseLeave(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form8: TForm8;
BitBtn:array[1..8,1..15] of TBitBtn;//二维数组组件的定义
BitBtnTemp:TBitBtn;//记录上次点击按钮的临时组件
implementation
{$R *.dfm}
procedure TForm8.BitBtn1Click(Sender: TObject);
begin
(Sender as TBitBtn).Visible:=False;
if BitBtnTemp=nil then
begin
BitBtnTemp:= (Sender as TBitBtn);
Exit;
end;
if not(BitBtnTemp=nil) then
begin
BitBtnTemp.Visible:=True;
BitBtnTemp:=(Sender as TBitBtn);
Exit;
end;
end;
procedure TForm8.BitBtn1MouseEnter(Sender: TObject);
var
BBTemp:TBitBtn;
PosX,PosY:Integer;
i,j:Integer;
begin
BBTemp:=(Sender as TBitBtn);
PosY:=BBTemp.Tag div 10;//10-150
PosX:=BBTemp.Tag mod 10;//1-8
Label2.Caption:=Char(PosX+64)+IntToStr(PosY div 10);//Char(65):A
for i := 1 to 8 do
begin
if i=PosX then
begin
for j := 1 to 15 do
begin
BitBtn[i,j].Kind:=bkRetry;
BitBtn[i,j].Caption:='&';
end;
end;
end;
for j := 1 to 15 do
begin
if j=(PosY div 10) then
begin
for i := 1 to 8 do
begin
BitBtn[i,j].Kind:=bkRetry;
BitBtn[i,j].Caption:='&';
end;
end;
end;
end;
procedure TForm8.BitBtn1MouseLeave(Sender: TObject);
var
i,j:Integer;
begin
Image1.Visible:=False;
for i := 1 to 8 do
begin
for j := 1 to 15 do
begin
if BitBtn[i,j].Kind=bkRetry then
begin
BitBtn[i,j].Kind:=bkCustom;
BitBtn[i,j].Glyph:=nil;
BitBtn[i,j].Caption:='';
end;
end;
end;
Image1.Visible:=True;//有时刷新会暴露按钮后的图片,不知何原因,故控制图片的显示时间
end;
procedure TForm8.Button1Click(Sender: TObject);
begin
Image1.Picture.Bitmap.LoadFromResourceName(HInstance,'ABNNEK'); //Load card1 模糊名称
if not(BitBtnTemp=nil) then
begin
BitBtnTemp.Visible:=True;
BitBtnTemp:=nil;
end;
end;
procedure TForm8.Button2Click(Sender: TObject);
begin
Image1.Picture.Bitmap.LoadFromResourceName(HInstance,'BBTKR'); //Load card2
if not(BitBtnTemp=nil) then
begin
BitBtnTemp.Visible:=True;
BitBtnTemp:=nil;
end;
end;
procedure TForm8.Button3Click(Sender: TObject);
begin
if Edit1.Text='mmm ' then
GroupBox2.Visible:=False;
end;
procedure TForm8.FormCreate(Sender: TObject);
var
i,j:Integer;
begin
SetWindowPos(Handle,HWND_TOPMOST,0,0,Self.Width,Self.Height,SWP_SHOWWINDOW);//令窗体在最前
for i := 1 to 8 do
begin
for j := 1 to 15 do
begin
BitBtn[i, j]:=TBitBtn.Create(Self);//动态创建组件,create参数多用self,也就是窗体本身
BitBtn[i, j].Parent:=Panel1;//动态创建组件,要正常显示需指定父容器
BitBtn[i, j].Width:=30;
BitBtn[i, j].Height:=28; //大小
BitBtn[i, j].Left:=29*(i-1);
BitBtn[i, j].Top:=26*(j-1); //位置
BitBtn[i, j].OnClick:=BitBtn1Click; //批量响应事件
BitBtn[i, j].OnMouseEnter:=BitBtn1MouseEnter;
BitBtn[i, j].OnMouseLeave:=BitBtn1MouseLeave;
BitBtn[i, j].TabStop:=False;
BitBtn[i, j].Tag:=100*j+i;//通过tag来识别组件
end;
end;
Image1.Picture.Bitmap.LoadFromResourceName(HInstance,'ABNNEK'); //Load card1 模糊名称
Edit1.SetFocus;
end;
procedure TForm8.Shape1MouseEnter(Sender: TObject);
begin
Shape1.Pen.Mode:=pmNop;//显示卡序号
end;
procedure TForm8.Shape1MouseLeave(Sender: TObject);
begin
Shape1.Pen.Mode:=pmWhite;//覆盖卡序号
end;
procedure TForm8.Timer1Timer(Sender: TObject);
begin
Clipboard.Clear;//引用Clipbrd单元,则可以直接调用Clipboard全局变量。
end;
end.