Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. //---------------------------------------------------------------------------
  10. __fastcall TForm1::TForm1(TComponent* Owner)
  11.         : TForm(Owner)
  12. {
  13.   SetControl_OnKeyPress();
  14. }
  15. //---------------------------------------------------------------------------
  16. void __fastcall TForm1::SetControl_OnKeyPress(void)
  17. {
  18.   TButton *bn;
  19.   TEdit *ed;
  20.   TListBox *lb;
  21.   TCheckBox *cb;
  22.   AnsiString name;
  23.   int ii;
  24.   for(ii=0;ii<ControlCount;ii++)
  25.   {
  26.     name=Controls[ii]->ClassName();
  27.     if(name=="TButton")
  28.     {
  29.       bn=(TButton *)Controls[ii];
  30.       bn->OnKeyPress=Pro_KeyPress;
  31.     }
  32.     else if(name=="TEdit")
  33.     {
  34.       ed=(TEdit *)Controls[ii];
  35.       ed->OnKeyPress=Pro_KeyPress;
  36.     }
  37.     else if(name=="TListBox")
  38.     {
  39.       lb=(TListBox *)Controls[ii];
  40.       lb->OnKeyPress=Pro_KeyPress;
  41.     }
  42.     else if(name=="TCheckBox")
  43.     {
  44.       cb=(TCheckBox *)Controls[ii];
  45.       cb->OnKeyPress=Pro_KeyPress;
  46.     }
  47.     else{}
  48.   }
  49. }
  50. //---------------------------------------------------------------------------
  51. void __fastcall TForm1::Pro_KeyPress(TObject *Sender, char &Key)
  52. {
  53.   if(Key==27)Close();
  54. }
  55. //---------------------------------------------------------------------------
  56. void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
  57. {
  58.   Pro_KeyPress(Sender, Key);
  59. }
  60. //---------------------------------------------------------------------------