如何设置Button点击事件功能,Borland Turbo c++?
我没有与设计器一起创建按钮,但我不知道如何为单击事件分配任何功能。
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]);
}
}
I've created Button not with designer, but i don't know how to assign any function for click event.
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]);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需将此分配用于事件处理程序:
tl [i][j]->OnClick = MyButtonClick;
您可以提供任何类方法(按名称)作为事件处理程序,其签名与为特定事件指定(在OnClick
的情况下,它应该是void __fastcall MethodName(TObject *Sender)
Simply use this assignment for event handler:
tl [i][j]->OnClick = MyButtonClick;
You can provide any class method (by name) as an event handler, which have the same signature as specified for certain event (in case ofOnClick
it should bevoid __fastcall MethodName(TObject *Sender)
最简单的事情就是双击该按钮,IDE 就会为您创建方法声明。就您而言,您似乎从某处复制/粘贴了一个并希望手动分配它。您可以在对象检查器中执行此操作。选择设计器中的按钮,然后单击对象检查器中的“事件”选项卡。然后,您可以将具有正确签名的任何现有函数分配给 OnClick 事件。
The easiest thing to do is just double click on the button and the IDE will create the method declarations for you. In your case, it looks like you copy/pasted one from somewhere and would like to assign it manually. You can do that in the object inspector. select the button in the designer, then click on the "events" tab in the object inspector. You can then assign any existing functions with the correct signature to the OnClick event.