c++ - 如何设置Button点击事件函数,Borland Turbo C++?

标签 c++ vcl borland-c++

我没有使用设计器创建 Button,但我不知道如何为点击事件分配任何功能。

TButton *tl[15][15];

void __fastcall TForm1::MyButtonClick(TObject *Sender)
{ 
   TButton *tlakt;
   tlakt=(TButton*)Sender;
   ...
}

__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{

   for (i=0;i<15;i++) for (j=0;j<15;j++){
    tl [i][j]=new TButton(this);
    tl [i][j]->Caption="";
    tl [i][j]->Width=24;
    tl [i][j]->Height=24;
    tl [i][j]->TabStop=false;
    tl [i][j]->Left=50+i*28;
    tl [i][j]->Top=50+j*28;
    tl [i][j]->Tag=i*100+j;
    /* SET MyButtonClick as EVENT FUNCTION */
    InsertControl (tl[i][j]);
   }
}

最佳答案

只需将此分配用于事件处理程序:tl [i][j]->OnClick = MyButtonClick; 您可以提供任何类方法(按名称)作为事件处理程序,它们具有相同的为特定事件指定的签名(如果是 OnClick,它应该是 void __fastcall MethodName(TObject *Sender)

关于c++ - 如何设置Button点击事件函数,Borland Turbo C++?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6289894/

相关文章:

c++ - 在 Borland C++ 编译器 5.5 中询问文件 .obj 和 .tds

c++ - 如何在 C++ 中将整个文本文件复制到 char 数组中

c++ - 32 位代码中 DWORD 与 QWORD 对齐的性能

C++ 函数名称分解 : What does this name suffix mean?

delphi - 在 Delphi 6 中加载特定帧会导致它立即退出

delphi - TPNGImage `LoadFromStream` 在某些情况下不工作

delphi - 编译不同Delphi版本的Delphi组件包(bpl)

必要时插入类型名的 C++ 宏

c++ - 使用 C++ (Linux) 更改 BlueFox3 相机的流帧速率?

c++ - OPENCV近距离物体检测