1,输入弹出辅助框,我用的是dbgrid做辅助框 procedure TfmCarInfo.LabeledEdit_AddPartChange(Sender: TObject); begin if Trim(LabeledEdit_AddPart.Text)<>'' then begin ADOQuery_CodeList.Close; ADOQuery_CodeList.SQL.Clear; ADOQuery_CodeList.SQL.Add(' select * from part where wshortname like '+'''%'+LabeledEdit_AddPart.Text+'%'''); ADOQuery_CodeList.Open; if ADOQuery_CodeList.RecordCount<>0 then begin DBGrid_PartList.Top:=LabeledEdit_AddPart.Top+LabeledEdit_AddPart.Height; DBGrid_PartList.Left:=LabeledEdit_AddPart.Left; DBGrid_PartList.Visible:=true; end; end else begin DBGrid_PartList.Visible:=false; end; end; 2,按下键,移动到辅助框 procedure TfmCarInfo.LabeledEdit_AddPartKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = 40 then begin if (DBGrid_PartList.Visible) then begin DBGrid_PartList.SetFocus; end; end; if key=VK_RETURN then DBGrid_PartList.Visible:=False; end; procedure TfmCarInfo.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); begin //截获鼠标左键单击,如果焦点不在相应的输入框和下拉列表中,则隐藏下拉列表 if Msg.message=WM_LBUTTONUP then begin if (Self.ActiveControl.Name<>'LabeledEdit_AddPart')then if (Self.ActiveControl.Name<>'DBGrid_PartList') then DBGrid_PartList.Visible:=false; end; end; procedure TfmCarInfo.ApplicationEvents1ShortCut(var Msg: TWMKey; var Handled: Boolean); begin //截获按TAB键事件,隐藏下拉列表 if (msg.CharCode=VK_TAB) then begin if Self.ActiveControl.Name='LabeledEdit_AddPart' then DBGrid_PartList.Visible:=false; end; end;
procedure TfmCarInfo.LabeledEdit_AddPartChange(Sender: TObject);
begin
if Trim(LabeledEdit_AddPart.Text)<>'' then
begin
ADOQuery_CodeList.Close;
ADOQuery_CodeList.SQL.Clear;
ADOQuery_CodeList.SQL.Add(' select * from part where wshortname like '+'''%'+LabeledEdit_AddPart.Text+'%''');
ADOQuery_CodeList.Open;
if ADOQuery_CodeList.RecordCount<>0 then
begin
DBGrid_PartList.Top:=LabeledEdit_AddPart.Top+LabeledEdit_AddPart.Height;
DBGrid_PartList.Left:=LabeledEdit_AddPart.Left;
DBGrid_PartList.Visible:=true;
end;
end
else
begin
DBGrid_PartList.Visible:=false;
end;
end;
2,按下键,移动到辅助框
procedure TfmCarInfo.LabeledEdit_AddPartKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = 40 then
begin
if (DBGrid_PartList.Visible) then
begin
DBGrid_PartList.SetFocus;
end;
end;
if key=VK_RETURN then
DBGrid_PartList.Visible:=False;
end;
procedure TfmCarInfo.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
//截获鼠标左键单击,如果焦点不在相应的输入框和下拉列表中,则隐藏下拉列表
if Msg.message=WM_LBUTTONUP then
begin
if (Self.ActiveControl.Name<>'LabeledEdit_AddPart')then
if (Self.ActiveControl.Name<>'DBGrid_PartList') then
DBGrid_PartList.Visible:=false;
end;
end;
procedure TfmCarInfo.ApplicationEvents1ShortCut(var Msg: TWMKey;
var Handled: Boolean);
begin
//截获按TAB键事件,隐藏下拉列表
if (msg.CharCode=VK_TAB) then
begin
if Self.ActiveControl.Name='LabeledEdit_AddPart' then
DBGrid_PartList.Visible:=false;
end;
end;