I use a panel and if the user Leftclicks an area with the mouse, I am trying to set the variable LeftRightClick to "Left" and the same for rightclick, "Right".

Then I call the button43_MouseDown event to show the correct MessageBox, depending on if it was a leftClick or RightClick.

When doing this the messageBox: MessageBox:: Show("LeftClick");
is always shown even that a rightclick was made.

I wonder why this is happening ?

String^ LeftRightClick; //Global Variable

private: System::Void panel1_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) 
{
	 if( e->Button == System::Windows::Forms::MouseButtons::Left )
	 {
		if( e->X >= 304 && e->X <= 346 && e->Y >= 369 && e->Y <= 392 )
		{
			 LeftRightClick = "Left";
		}
	 }
	 if( e->Button == System::Windows::Forms::MouseButtons::Right )
	 {
		if( e->X >= 304 && e->X <= 346 && e->Y >= 369 && e->Y <= 392 )
		{
			 LeftRightClick = "Right";
		}
	 }
	 button43_MouseDown(nullptr, nullptr);
}







private: System::Void button43_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) 
{
	 if( LeftRightClick == "Left" )
	 {
		MessageBox::Show("LeftClick");
	 }
	 if( LeftRightClick == "Right" )
	 {
		MessageBox::Show("RightClick");
	 }
}

You can get which button was pressed via the e->Button member of the MouseEventArgs object. I don't know your design (sounds scary with all those controls lol) so I'm not sure what the button43 has to do with it, but you can get a MouseEventArgs in the button43_MouseDown if you need it.
I'm not sure what's causing the phenomenon that you are observing but perhaps if you are clicking again before everything is set your string is reflecting the old value(?).
If you really need information to pass from event handler to event handler then you can inherit from the MouseEventArgs and add what you need to it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.