菜鸟上路请高人指点啊。。。
void _fastcall TForm1::ActiveControlChanged(System::TObject *Sender)
{
for (int I = 0; I < Form1->ControlCount; I++)
{
TWidgetControl *Temp = dynamic_cast<TWidgetControl *>(Form1->Controls[I]);
if (Temp && Temp->Focused())
{
StatusBar1->SimpleText = GetLongHint(Temp->Hint);
return;
}
}
}
中间两句是什么意思?
原文如下:
This example uses the OnActiveControlChange event to detect when focus changes on the form. When focus changes, the hint for the active control is displayed on the status bar. To use this example, you must add a status bar to the form and set its SimplePanel property to true.
Add a new public procedure, ActiveControlChanged, to the TForm1 class declaration in the header file.
Implement this procedure as follows:
void _fastcall TForm1::ActiveControlChanged(System::TObject *Sender)
{
for (int I = 0; I < Form1->ControlCount; I++)
{
TWidgetControl *Temp = dynamic_cast<TWidgetControl *>(Form1->Controls[I]);
if (Temp && Temp->Focused())
{
StatusBar1->SimpleText = GetLongHint(Temp->Hint);
return;
}
}
}
Assign this method as the OnActiveControlChange event handler by setting it from the form's OnCreate event handler (Be sure that the form's OldCreateOrder property is false):
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Screen->OnActiveControlChange = ActiveControlChanged;
}
Make sure you clean up the screen object when the form is freed by adding this OnDestroy event handler to the form (Be sure that the form's OldCreateOrder property is false):
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
Screen->OnActiveControlChange = 0;
}
[解决办法]
// 窗体创建时,接管全局对象Screen的OnActiveControlChange事件,当活动的组件有变化时(焦点转移到其他控件),将调用 ActiveControlChanged 函数进行处理
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Screen->OnActiveControlChange = ActiveControlChanged;
}
// 窗体销毁时,不再接管Screen对象的OnActiveControlChange事件
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
// 这里其实应该用NULL比较容易理解
Screen->OnActiveControlChange = 0;
}
[解决办法]
几个edit公用click事件,可以获得具体控件的name
void __fastcall TForm2::Edit1Click(TObject *Sender)
{
Caption = ((TEdit*)Sender)->Name;
}