开发者

C# 2 controls, both need to catch diffrent keypresses, even while one has no focus

I'm trying to make some sort of intellisense look a like for an editor I'm working on. When the user types in the richtextbox and the letters match a word a listview will pop-up and the matched word will be selected.

the problem is the focus is still on the richtextbox s开发者_Python百科o all the key presses will go to that control, which is good, except that if there's a match I need the Return and arrow keys to trigger in the listview and not in the richtextbox.

is there some way of using the keypress event of the richtextbox to send those keys to the listview?

thanks


Would it not be easier to use scintilla, the .NET wrapper can be found here, which would do all of what you are looking for?

Edit: It looks like someone has done this, in what you are trying to achieve, an article about it is on CodeProject.


I think it is good that the focus remains on the richtextbox.

How about subclassing that listview to add methods like void SelectNext(), void SelectPrevious(), and string PerformCompletion(). You handle mouse events only for the richtextbox. If the textbox is visible, and the user presses a down arrow, call SelectNext() and swallow the keypress, but if it is not visible, just navigate down to the next line (let the keypress through).

If the listview is visible and the user presses Enter or Tab or . or whatever, call PerformCompletion() to get the selected string, then add whatever characters haven't already been entered.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜