将上下文菜单项添加到操作系统范围内的所有文本框
我知道可以扩展标准文件的上下文菜单,但是有没有办法将项目添加到系统范围的文本框上下文菜单中?
这样新项目就会出现在用户可以在窗口中的任何位置键入的每个文本框中吗?
例如,允许添加诸如根据拼写检查器查找所选文本之类的功能。
I know it is possible to extend the context menu of the standard file however is there a way to add items to the system-wide text box context menu?
This would be so the new item appears in every text box that a user can type in anywhere in windows?
For example to allow to add such features as look up the selected text against a spell checker.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这对于 C# 在技术上是不可能的。
让我们想象一下接下来的情况。假设您已成功编写托管扩展,并且它“扩展”了系统中的任何文本框上下文菜单。当然,您应该处理添加的每个新菜单项。为了实现这一点,您应该将托管代码注入到每个具有文本框的进程并替换其
WindProc
。好的,假设系统中有一个托管应用程序,它是为 .net 版本编写的,与您用于扩展的版本不同。因此,在这种情况下,您将在扩展注入期间遇到严重错误,因为每个进程只能加载一个版本的 .net。因此,无法编写健壮的托管低级钩子或 shell 扩展。来自此处:您还可以查看此< /a> 文章并探讨为什么不应该编写托管 shell 扩展。
This is technically impossible with C#.
Lets imagine next situation. Suppose you have sucessfuly write your managed extention and it "extends" any textbox context menu in the system. And of course you should handle each new menu item you have added. and to achieve this you should inject your managed code to each process which has textbox and replace its
WindProc
. OK, suppose there is managed app in the system which was writen for .net version different from version you used for your extention. So in this case you would got critical error during extension injection because ONLY one version of .net could be loaded per process. SO there is no way to write robust managed low level hook or shell extension. From here:You also may check this article and explore why you shouldnt write managed shell extensions.
从您尝试使用的文本框继承并在其中添加默认值。使用您的类而不是文本框类。
Inherit from the text box you're trying to use and add the default value there. Use your class instead of the text box class.
您必须添加鼠标挂钩
并且然后当您单击的窗口/控件是文本框时弹出上下文菜单。
这可能(并且可能会)干扰已经存在的上下文菜单,因为您将隐藏它们或与它们发生冲突。
(虽然这是一个可怕的计划......)
You would have to add a Mouse Hook
And then pop up a context menu when the window/control you are clicking is a textbox.
This might (and probably will) interfere with already present context menus because you will be hiding them or clashing with them.
(A horrible plan though...)
使用表单和上下文菜单调用 Bind 方法。
如果添加动态文本框,则将其放在 Bind 方法的开头:
每当将控件添加到窗体或另一个控件时,这都会调用 Bind 方法。
Call the Bind method with the form and context menu.
If you adding a dynamic textbox, then place this at the beggining of the Bind method:
This causes the Bind method to called, whenever a control is added to the form or another control.