实现ComboBox输入文字的自动完成

时间:2010-04-23 17:28:47  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:elete 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_FI...
  正文: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输入文字的自动完成"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/VC/2010-04-23/13759.html


关键字:

关于《实现ComboBox输入文字的自动完成》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td