我需要一个具有自动完成功能的备忘录。最终,我希望能够在用户按下类似于Delphi IDE自动完成的热键(Ctrl-space)时显示一个自定义的自动完成列表。
我有TMS的AdvMemo,但老实说,这个特殊的组件缺乏帮助。AdvMemo似乎支持自定义自动补全,但我似乎找不到如何显示列表。
因此,如果任何人有任何建议来实现备忘录中的自动完成,或者启发我使用AdvMemo,将不胜感激
发布于 2011-06-14 15:58:20
我决定使用TPopupmenu作为自动完成列表,为TMemo编写一些处理程序。
阅读这篇文章的读者请参考我的另一篇文章:Delphi - Get the whole word where the caret is in a memo (感谢RRUZ)
以及以下代码:用于AutoComplete TPopupMenu的OnPopup:(memoAutoComplete保存自动完成项的列表)
procedure AutoCompletePopup(Sender: TObject);
var i : integer;
NewItem : TMenuItem;
AutoCompleteToken: String;
begin
//filter list by token
AutoCompleteToken := SelectWordUnderCaret(edtComment);
AutoComplete.Items.Clear;
for i:=0 to memoAutoComplete.Lines.Count -1 do
begin
if SameText(LeftStr(memoAutoComplete.Lines.Strings[i],Length(AutoCompleteToken)),AutoCompleteToken) then
begin
NewItem := TMenuItem.Create(AutoComplete);
NewItem.Caption := memoAutoComplete.Lines.Strings[i];
NewItem.OnClick := AutoComplete1Click;
NewItem.OnMeasureItem := AutoComplete1MeasureItem;
NewItem.OnAdvancedDrawItem := AutoComplete1AdvancedDrawItem;
AutoComplete.Items.Add(NewItem);
end;
end;
end;至于Tmemo:
procedure Memo1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var pt : TPoint;
begin
if (Key = VK_SPACE) and (GetKeyState(VK_CONTROL) < 0) then
begin
pt := Memo1.ClientToScreen(Point(0,Memo1.Height));
AutoComplete.Popup(pt.X,pt.Y);
end;
end;发布于 2011-06-14 13:48:08
你可以看看SynEdit。它是免费的,开源的,并且有一个活跃的社区,当你遇到困难时可以帮助你。
https://stackoverflow.com/questions/6338426
复制相似问题