⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 有视频
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
  switch(Key)
  {
    case '0':		//接受数字键0~9的输入
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
    case 8:		//这是一个BackSpace键,不能禁止,否则不能实现删除功能了
      break;
    case '.':		//检查是否已存在小数点
      if(DotInStr(Edit1->Text))
        Key=0;
      break;
    case '+':		//检查是否已存在符号
    case '-':
      if(SignInStr(Edit1->Text))
        Key=0;
      break;
    default:		//对于其他输入键,置Key=0
      Key=0;
      break;
  }
}
//---------------------------------------------------------------------------
bool __fastcall TForm1::DotInStr(AnsiString ass)
{
  int ii,ll;
  ll=ass.Length();
  for(ii=0;ii<ll;ii++)
  {
    if(ass.c_str()[ii]=='.')
    {
      return True;
    }
  }
  return False;
}
//该函数检查字符串前面是否已存在"+、-"符号
bool __fastcall TForm1::SignInStr(AnsiString ass)
{
  int ii,ll;
  ll=ass.Length();
  for(ii=0;ii<ll;ii++)
  {
    if((ass.c_str()[ii]=='+')||(ass.c_str()[ii]=='-'))
    {
      return True;
    }
  }
  return False;
}

⌨️ 快捷键说明

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