2011-11-18 24 views
0

它應該在c#中像這樣工作,但C++/cli中的等價物是什麼?如何檢查在C++/cli中的MouseClick事件期間點擊了哪個鼠標按鈕?

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 
      } 
} 
+0

發佈的C#代碼無關.. 。爲什麼不發佈你擁有的C++/CLI代碼? – Marlon

回答

1

here你似乎缺少::之前你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(); 
    } 
+0

哦,它需要::在MouseButtons前面...... – marc40000

+0

但是爲什麼? MouseButtons在System.Windows.Forms中聲明。不在前面的意思是我想要一些全局名稱空間的MouseButtons? – marc40000

+0

現在我無法將這個答案視爲正確。我已經嘗試過了。我必須等10分鐘左右...... – marc40000

相關問題