WORD lastkey ;
//—————————————————————————
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
String value = ComboBox1->Text ;
// If the user tried to delete he must not want to change anything.
if (lastkey == ‘\b’ || lastkey == VK_DELETE)
{
lastkey = 0 ;
return ;
}
lastkey = 0 ;
// 确保利用者没有在中间插入字符
if (ComboBox1->SelStart != value.Length ())
return ;
// 在下拉列表中寻找匹配项.
int index = SendMessage (ComboBox1->Handle, CB_FINDSTRING, -1, (LPARAM) value.c_str ()) ;
if (index >= 0)
{
// 找到匹配项并显示.
ComboBox1->ItemIndex = index ;
String newtext = ComboBox1->Text ;
SendMessage (ComboBox1->Handle, CB_SETEDITSEL, 0, MAKELPARAM (value.Length (), -1)) ;
}
}
//—————————————————————————
void __fastcall TForm1::ComboBox1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
// 按下的最后一个键值.
lastkey = Key ;
}
//—————————————————————————
实现ComboBox输入文字的自动完成
最后更新 2017-11-05 08:00 星期日 所属:
C语言/C++ 教程 浏览:513