如何检查在 c++/cli 中的 MouseClick 事件期间单击了哪个鼠标按钮?

发布于 2024-12-17 00:35:21 字数 671 浏览 1 评论 0原文

它应该在 C# 中像这样工作,但是在 C++/cli 中等效的是什么?

private void CustomControl_MouseClick(object sender, MouseEventArgs e) 
{        
   if (e.Button == MouseButtons.Right) 
   { 
     ... do something
   } 
} 

MouseButtons.Right、MouseButtons::Right 和 MouseButtons->Right 似乎都无法编译。它总是说

error C2039: 'Right' : is not a member of 'System::Enum'

这是我的 c++/cli 代码:

System::Void WindowTest::pictureBoxTest_MouseClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e)
    {
        if (e->Button == MouseButtons::Left)
        {
        // do something
            }
}

It's supposed to work like this in c#, but what's the equivalent in c++/cli?

private void CustomControl_MouseClick(object sender, MouseEventArgs e) 
{        
   if (e.Button == MouseButtons.Right) 
   { 
     ... do something
   } 
} 

MouseButtons.Right, MouseButtons::Right and MouseButtons->Right all don't seem to compile. It always says

error C2039: 'Right' : is not a member of 'System::Enum'

Here is my c++/cli code:

System::Void WindowTest::pictureBoxTest_MouseClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e)
    {
        if (e->Button == MouseButtons::Left)
        {
        // do something
            }
}

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

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

发布评论

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

评论(1

浅黛梨妆こ 2024-12-24 00:35:21

此处 您似乎缺少 < code>:: 在 MouseButtons::Right 之前

  void panel1_MouseDown( Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e )
  {
     // Update the mouse path with the mouse information
     Point mouseDownLocation = Point(e->X,e->Y);
     String^ eventString = nullptr;
     switch ( e->Button )
     {
        case ::MouseButtons::Left:
           eventString = "L";
           break;

        case ::MouseButtons::Right:
           eventString = "R";
           break;

        case ::MouseButtons::Middle:
           eventString = "M";
           break;

        case ::MouseButtons::XButton1:
           eventString = "X1";
           break;

        case ::MouseButtons::XButton2:
           eventString = "X2";
           break;

        case ::MouseButtons::None:
        default:
           break;
     }
     if ( eventString != nullptr )
     {
        mousePath->AddString( eventString, FontFamily::GenericSerif, (int)FontStyle::Bold, (float)fontSize, mouseDownLocation, StringFormat::GenericDefault );
     }
     else
     {
        mousePath->AddLine( mouseDownLocation, mouseDownLocation );
     }

     panel1->Focus();
     panel1->Invalidate();
  }

From here you seem to be missing the :: before your MouseButtons::Right

  void panel1_MouseDown( Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e )
  {
     // Update the mouse path with the mouse information
     Point mouseDownLocation = Point(e->X,e->Y);
     String^ eventString = nullptr;
     switch ( e->Button )
     {
        case ::MouseButtons::Left:
           eventString = "L";
           break;

        case ::MouseButtons::Right:
           eventString = "R";
           break;

        case ::MouseButtons::Middle:
           eventString = "M";
           break;

        case ::MouseButtons::XButton1:
           eventString = "X1";
           break;

        case ::MouseButtons::XButton2:
           eventString = "X2";
           break;

        case ::MouseButtons::None:
        default:
           break;
     }
     if ( eventString != nullptr )
     {
        mousePath->AddString( eventString, FontFamily::GenericSerif, (int)FontStyle::Bold, (float)fontSize, mouseDownLocation, StringFormat::GenericDefault );
     }
     else
     {
        mousePath->AddLine( mouseDownLocation, mouseDownLocation );
     }

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