LoginSignup
0
0

More than 5 years have passed since last update.

C++ Builder XE4 > 45個のボタンを持つフォーム。ボタンを押したら名前をTMemoに表示

Last updated at Posted at 2019-01-23
動作環境
C++ Builder XE4

処理概要

  • 45個のTButtonを用意
  • 各ボタンを押した時、その名前をTMemoに表示する

イベント設定

Button1を配置する。
オブジェクトインスペクタの「イベント」タブにて、「OnClick」をButtonXClick_generalという名前にする。
ButtonXClick_generalは以下の実装を行う。
実装後、Button1をコピーして、45個のButtonをフォームに配置する。

2019-01-23_14h34_42.png

実装

Unit1.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)
{
    Memo1->Lines->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonXClick_general(TObject *Sender)
{
    TButton *btnPtr = (TButton *)Sender;
    Memo1->Lines->Add(btnPtr->Name);
}
//---------------------------------------------------------------------------

フォームデザイン

2019-01-23_14h32_31.png

実行例

2019-01-23_14h33_09.png

作成の理由

マウス自動クリックのソフトを実装し、そのテストに使う。

  • auto click the mouse
    • Delphi実装例
      • フォーカスがクリック先のソフトに移る
      • 自分のソフトにフォーカスを戻す処理で失敗したりする
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0