鼠标按钮::在 c++/cli 中向左
我想检查一下左侧按钮是否被按下。
我对 Msdna 感到愤怒:
if(e->Button == MouseButtons.Left) {...}
//or
if(e->Button == ::MouseButtons.Left) {...}
但它们都没有编译通过。
I would like to check the left button is the pressed one.
I red on Msdna:
if(e->Button == MouseButtons.Left) {...}
//or
if(e->Button == ::MouseButtons.Left) {...}
But no one of them compiles.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是C++语言的一个烦恼,由C++/CLI继承。它将类型名称和类成员名称放在同一个符号表中。当您使用 C++/CLI 而不是 C# 或 VB.NET(将类型标识符分开的语言)编写 Winforms 代码时,这是您经常会遇到的问题。
MouseButtons 枚举类型和 Form 类的 MouseButtons 属性之间存在歧义,它们都在此处的范围内。 IntelliSense 不再帮助您获得正确的语法,这可能就是您最终得到的结果。而不是 :: 不再有机会获得像样的编译器错误消息。您可以通过完整地编写枚举类型名称来解决歧义:
像这样的问题可能是 C++/CLI 从未变得非常流行的原因之一。话又说回来,C# 是一种集体行为。受到推崇的。
This is an annoyance of the C++ language, inherited by C++/CLI. It puts the names of types and the names of class members in the same symbol table. This is something you'll battle often when you write Winforms code in C++/CLI instead of C# or VB.NET, languages that keep type identifiers separate.
There's an ambiguity between the MouseButtons enum type and the Form class' MouseButtons property, they are both in scope here. IntelliSense stops helping you to get the syntax right which is probably how you ended up with . instead of :: Leaving no odds anymore to get a decent compiler error message. You resolve the ambiguity by writing the enum type name in full:
Problems like these are probably one reason that C++/CLI never got very popular. Then again, C# is rather a class act. Recommended.
您需要将事件挂接到您想要的控件上:
并像这样处理它:
You need to hook the event on control you want:
and handle it like this: