5 个解决方案
#1
判断和设置Edit的SelStart属性即可。
#2
void __fastcall TForm1::edt1KeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
if( Key == VK_RIGHT )
{
if( edt1->SelStart == edt1->Text.Length() )
{
edt2->SelStart = 1 ;
edt2->SelLength = 0 ;
edt2->SetFocus() ;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::edt2KeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
if( Key == VK_LEFT )
{
if( edt2->SelStart == 0 )
{
edt1->SelStart = edt1->Text.Length() ;
edt1->SelLength = 0 ;
edt1->SetFocus();
}
}
}
为什么从edt1跳到edt2或者反过来的时候都是全选的呢,而且光标都是在字符串的最后.
#3
void __fastcall TForm1::Edit1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == VK_RIGHT)
{
if (Edit1->SelStart == Edit1->Text.Length())
{
Edit2->SetFocus();
Edit2->SelStart = 0;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit2KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == VK_LEFT)
{
if (Edit2->SelStart == 0)
{
Edit1->SetFocus();
Edit1->SelStart = Edit1->Text.Length();
}
}
}
#4
额,,设置焦点的顺序反了.
#5
正解
#1
判断和设置Edit的SelStart属性即可。
#2
void __fastcall TForm1::edt1KeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
if( Key == VK_RIGHT )
{
if( edt1->SelStart == edt1->Text.Length() )
{
edt2->SelStart = 1 ;
edt2->SelLength = 0 ;
edt2->SetFocus() ;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::edt2KeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
if( Key == VK_LEFT )
{
if( edt2->SelStart == 0 )
{
edt1->SelStart = edt1->Text.Length() ;
edt1->SelLength = 0 ;
edt1->SetFocus();
}
}
}
为什么从edt1跳到edt2或者反过来的时候都是全选的呢,而且光标都是在字符串的最后.
#3
void __fastcall TForm1::Edit1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == VK_RIGHT)
{
if (Edit1->SelStart == Edit1->Text.Length())
{
Edit2->SetFocus();
Edit2->SelStart = 0;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit2KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == VK_LEFT)
{
if (Edit2->SelStart == 0)
{
Edit1->SetFocus();
Edit1->SelStart = Edit1->Text.Length();
}
}
}
#4
额,,设置焦点的顺序反了.
#5
正解