它应该在c#中这样工作,但是c ++ / cli中的等价物是什么?
private void CustomControl_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
... do something
}
}
MouseButtons.Right,MouseButtons :: Right和MouseButtons->对所有人来说似乎都没有编译。它总是说
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 :(得分: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();
}