老大,怎样让combobox控件实现IE网址输入框的功能,最主要是能自动筛选的功能。先谢了

解决方案 »

  1.   

    unit CompletingComboBox;interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;typeTCompletingComboBox = class(TComboBox)privateFTextCompletion: Boolean;function GetTextCompletion: Boolean;procedure SetTextCompletion(const Value: Boolean);protected// override the WndProc() so that we can trap KeyUp events.procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd;ComboProc: Pointer); override;public{ Public declarations }publishedproperty TextCompletion: Boolean read GetTextCompletion write SetTextCompletion;end;procedure Register;implementationprocedure Register;beginRegisterComponents('Standard', [TCompletingComboBox]);end;{ TCompletingComboBox }function TCompletingComboBox.GetTextCompletion: Boolean;beginResult := fTextCompletion;end;procedure TCompletingComboBox.SetTextCompletion(const Value: Boolean);beginfTextCompletion := Value;end;procedure TCompletingComboBox.ComboWndProc(var Message: TMessage; ComboWnd: HWnd;ComboProc: Pointer);varrc, len: Integer;begininherited;case Message.Msg ofWM_KEYUP:begin// test to see if its a character that should not be processed.if (Message.WParam <> 8) and (Message.WParam <> VK_DELETE) and(Message.WParam <> VK_SHIFT) and (FTextCompletion = True) thenbegin// Use CB_FINDSTRING to locate the string in the Items propertyrc := Perform(CB_FINDSTRING, -1, Integer(PChar(Caption)));// if its in there then add the new string to the Text and// select the portion that wasn't typed in by the userif rc <> CB_ERR thenbegin// store the length of the current stringlen := Length(Text);// set the new stringItemIndex := rc;// highlight the rest of the text that was added.SelStart := len;SelLength := Length(Text) - len; // return 0 to signify that the message has been handled.Message.Result := 0;end;end;end;end; // caseend;end.*************************Combobox的自动完成在Combobox的OnChange或者Key事件中,写如下代码,注意,没有处理删除的情况,请自己完成。procedure TForm1.ComboBox1Change(Sender: TObject);vara:integer;Old:string;begina:=-1;Old :=ComboBox1.Text;sendmessage(combobox1.handle,CB_SHOWDROPDOWN,1,0);a:=SendMessage(ComboBox1.Handle, CB_SELECTSTRING,integer(@a),integer(pchar(ComboBox1.Text)));ComboBox1.SelStart:=Length(Old);ComboBox1.SelLength:=Length(ComboBox1.Text)-Length(Old);ComboBox1.ItemIndex:=a;end;***********unit unit1....privateselectitem : boolean;....procedure TForm1.ComboBox1Change(Sender: TObject);varsinput, sselected : string;i, j : integer;beginj := 0;if not selectitem thenbeginselectitem := true;exit;end;sinput := copy(combobox1.text, 1, combobox1.SelStart);for i := 0 to combobox1.items.count - 1 doif copy(combobox1.items[i], 1, length(sinput)) = sinput thenbeginif j = 0 then sselected := combobox1.items[i];j := j + 1;end;if j > 0 then combobox1.Text := sselectedelse combobox1.Text := sinput;combobox1.SelStart := length(sinput);combobox1.SelLength := length(combobox1.text) - length(sinput);end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);beginapplication.Terminateend;procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);beginif key = 8 then selectitem := false;end;procedure TForm1.FormShow(Sender: TObject);beginselectitem := true;end;end.摘自 超级猛料2003 CHM版本
      

  2.   

    介绍一个TComboBox98的控件,你到网上搜索一下就行了