unit1.cpp

来自「有视频」· C++ 代码 · 共 63 行

CPP
63
字号
//---------------------------------------------------------------------------
#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);

}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?