You can assign the same event to multiple controls. When called the "object sender" portion will be a reference to whatever one of the controls was clicked.
The EventArgs portion is a way to pass extra information to the event handler. Some events use a derivative of EventArgs which contain extra information.

The function will be defined somethng like this (like any function thats auto generated for a form object):

private: System::Void MySpecialFunction_Click(System::Object^  sender, System::EventArgs^  e)

Enter the funciton name in the form objects click event property

In the function we can do this:-

	if (sender == btnMyButton)		//Was sender a specific control / object:

Or if we want to get at some property of the sender (for instance its state or its text field):

	ToolStripMenuItem ^ClickedItem = dynamic_cast<toolstripmenuitem^>(sender);
	if (ClickedItem != nullptr)
		String ^MyString = ClickedItem->Text;
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.