C# 从文本框中禁用默认窗口上下文条

发布于 2024-12-21 17:36:09 字数 137 浏览 3 评论 0原文

我已禁用整个表单中的默认上下文条,并用我自己的上下文条替换。 在我的上下文菜单条中,我有一个工具条文本框,但是在其中右键单击时,它会显示默认的 Windows 上下文菜单。 预先感谢您的所有回复, 问候, 戴夫

I have disabled the default context strip throughout my form, and replaced with my own.
Within my contextmenustrip i have a toolstriptextbox, however when right-clicking within this it brings up the default windows context menu..
Thanks in advance for any and all replies,
Regards,
Dave

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃兔兔 2024-12-28 17:36:09

删除默认右键单击菜单的最简单方法是定义您自己的(空)菜单:

myTextBox.ContextMenuStrip = new ContextMenuStrip();

这将在一行中删除默认的 Windows 右键单击​​选项。了解键盘快捷键(Ctrl-CCtrl-XCtrl -VCtrl-ACtrl-Z)仍然有效;您没有禁用基本功能,只是禁用鼠标访问它。

对于另一个 TextBox 的 ContextMenu 中的 TextBox,这有点棘手,但基本上您可以使用该项目的 TextBox 属性直接访问 ToolStripItem 中包含的 TextBox。此属性是一个普通的 System.Windows.Forms.TextBox,与您应用中的任何其他属性一样:

myToolStripTextBox.TextBox.ContextMenuStrip = new ContextMenuStrip();

Easiest way to remove the default right-click menu is to define your own (empty) menu:

myTextBox.ContextMenuStrip = new ContextMenuStrip();

This will, in one line, remove the default Windows right-click options. Understand that the keyboard shortcuts (Ctrl-C, Ctrl-X, Ctrl-V, Ctrl-A, Ctrl-Z) will all still work; you're not disabling the basic functionality, just the mouse-able access to it.

For a TextBox within a ContextMenu of another TextBox, it's a little trickier, but basically you can directly access the TextBox that is contained within the ToolStripItem, using the item's TextBox property. This property is a vanilla System.Windows.Forms.TextBox, like any other you'd have in your app:

myToolStripTextBox.TextBox.ContextMenuStrip = new ContextMenuStrip();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文