mainform.cpp

来自「C++ BUILDER精彩编程实例集锦(源码) 第一部分 界面设计 第二部分」· C++ 代码 · 共 111 行

CPP
111
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "MainForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

AnsiString  __fastcall TForm1::GetMessageBoxReturn(int i)
{
   AnsiString StrRtn="";
   switch(i)
   {
   case IDABORT:
      StrRtn="中断";
      break;
   case IDCANCEL:
      StrRtn="取消";
      break;
   case IDIGNORE:
      StrRtn="忽略";
      break;
   case IDNO:
      StrRtn="否";
      break;
   case IDOK:
      StrRtn="确定";
      break;
   case IDRETRY:
      StrRtn="重试";
      break;
   case IDYES:
      StrRtn="是";
      break;
   }
   return StrRtn;
}
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
  int i=0;
  i=MessageBox(NULL,"需要退出程序吗?","消息框风格一",MB_YESNOCANCEL);
  this->Caption="您刚才选择了'"+this->GetMessageBoxReturn(i)+"'按钮";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
  int i=0;
  i=MessageBox(NULL,"干得好!","消息框风格二",MB_ICONWARNING);
  this->Caption="您刚才选择了'"+this->GetMessageBoxReturn(i)+"'按钮";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
  int i=0;
  i=MessageBox(NULL,"请看帮助文件","消息框风格三",MB_ICONQUESTION);
  this->Caption="您刚才选择了'"+this->GetMessageBoxReturn(i)+"'按钮";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn4Click(TObject *Sender)
{
  int i=0;
  i=MessageBox(NULL,"操作违规","消息框风格四",MB_ICONERROR);
  this->Caption="您刚才选择了'"+this->GetMessageBoxReturn(i)+"'按钮";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn5Click(TObject *Sender)
{
  int i=0;
  i=MessageBox(NULL,"请看帮助文件","消息框风格五",MB_HELP);
  this->Caption="您刚才选择了'"+this->GetMessageBoxReturn(i)+"'按钮";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn6Click(TObject *Sender)
{
  int i=0;
  i=MessageBox(NULL,"刚才的操作正确吗?","消息框风格六",MB_OKCANCEL);
  this->Caption="您刚才选择了'"+this->GetMessageBoxReturn(i)+"'按钮";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn7Click(TObject *Sender)
{
  int i=0;
  i=MessageBox(NULL,"是否重试一次?","消息框风格七",MB_RETRYCANCEL);
  this->Caption="您刚才选择了'"+this->GetMessageBoxReturn(i)+"'按钮";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn8Click(TObject *Sender)
{
  int i=0;
  i=MessageBox(NULL,"是否重试一次?","消息框风格八",MB_YESNO);
  this->Caption="您刚才选择了'"+this->GetMessageBoxReturn(i)+"'按钮";
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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