Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- SetControl_OnKeyPress();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::SetControl_OnKeyPress(void)
- {
- TButton *bn;
- TEdit *ed;
- TListBox *lb;
- TCheckBox *cb;
- AnsiString name;
- int ii;
- for(ii=0;ii<ControlCount;ii++)
- {
- name=Controls[ii]->ClassName();
- if(name=="TButton")
- {
- bn=(TButton *)Controls[ii];
- bn->OnKeyPress=Pro_KeyPress;
- }
- else if(name=="TEdit")
- {
- ed=(TEdit *)Controls[ii];
- ed->OnKeyPress=Pro_KeyPress;
- }
- else if(name=="TListBox")
- {
- lb=(TListBox *)Controls[ii];
- lb->OnKeyPress=Pro_KeyPress;
- }
- else if(name=="TCheckBox")
- {
- cb=(TCheckBox *)Controls[ii];
- cb->OnKeyPress=Pro_KeyPress;
- }
- else{}
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Pro_KeyPress(TObject *Sender, char &Key)
- {
- if(Key==27)Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
- {
- Pro_KeyPress(Sender, Key);
- }
- //---------------------------------------------------------------------------