怎么用键盘下的enter键在一个窗体间的各个控件间切换
如何用键盘上的enter键在一个窗体间的各个控件间切换
我在一个窗体上有很多控件,button1, button2 , edit1, edit2, radio1,radio2.
如何通过按下enter键来在上面的各个控件之间切换呢。
------解决方案--------------------
Form的KeyPreview设为true
但是button1不合适吧,button按enter是单击事件
------解决方案--------------------
在Form的OnKeyPress事件中处理。不过对于Button来说,按回车键相当于点击。对Edit和RadioButton有意义。
还有,记的将Form的KeyPreview属性设为true
我在一个窗体上有很多控件,button1, button2 , edit1, edit2, radio1,radio2.
如何通过按下enter键来在上面的各个控件之间切换呢。
------解决方案--------------------
Form的KeyPreview设为true
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if( Key == 13 )
{
SelectNext(this->ActiveControl,true,true);
}
}
但是button1不合适吧,button按enter是单击事件
------解决方案--------------------
在Form的OnKeyPress事件中处理。不过对于Button来说,按回车键相当于点击。对Edit和RadioButton有意义。
void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
{
if (Key == VK_RETURN)
{
Key = 0;
::SendMessage(Handle, WM_NEXTDLGCTL, 0, 0);
}
}
还有,记的将Form的KeyPreview属性设为true
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
KeyPreview = true;
}