delphi中Memo1下拉ListBox2选择完成文本填充
拖一个Memo1下拉ListBox2到界面上,假设ListBox2,里已加载列名
最终效果:
Memo1里输入.点号,带出ListBox2,选择好列名,回车,将点号和列名输入到Memo1原位置
procedure TForm8.Memo1KeyPress(Sender: TObject; var Key: Char); var a:ansiString; var pt: TPOint; // Memo1 弹出listbox2的位置 begin if (Key='.') then begin //============= 弹出 ListBox2m 并获得 焦点=========== ================= GetCaretPos(pt); ListBox2.Top := Memo1.Top + pt.y + memo1.Font.Size*2; ListBox2.left := Memo1.Left+ pt.x +11; ListBox2.BringTofront; ListBox2.Visible:=True;if ListBox2.CanFocus then ListBox2.SetFocus; //===================================================================== Key:=#0; end else ListBox2.Visible:= false; end;
procedure TForm8.ListBox2KeyPress(Sender: TObject; var Key: Char); begin if key=#27 then begin listbox2.Visible:=false; exit end; // Esc 隐藏ListBox2 if key =#13 then begin Memo1.SelText := '.'+listBox2.Items[listBox2.ItemIndex] ; //将 文本插入到Memo1 listbox2.Visible:=false; memo1.SetFocus; end; end;
鼠标双击,将 点选项 输入到Memo1
鼠标双击也选择项
procedure TForm8.ListBox2DblClick(Sender: TObject); begin if ListBox2.ItemIndex >= 0 then begin Memo1.SelText := '.'+listBox2.Items[listBox2.ItemIndex] ; //将 文本插入到Memo1 listbox2.Visible:=false; memo1.SetFocus; end; end;