The caption is the Text.
So you can do for example, for a RadioButton :
System::String^ sText = ((System::Windows::Forms::RadioButton^)sender)->Text;
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
When I create an event in a C++ program, for example a radio button click event, the compiler generates an event handler like this:
private: System::Void EnableX_Click(System::Object^ sender, System::EventArgs^ e) {
// I added this code to change the checked state of the button "Enable_1"
if (this->Enable_1->Checked) this->Enable_1->Checked = false; else this->Enable_1->Checked = true;
}
I have twenty buttons in my app, all doing pretty much the same thing. However, I would like to have one handler that handles all the buttons, using the button caption to identify which button is clicked.
I note that "sender" has the caption "01" in its parameters if I put a breakpoint on this line and inspect "sender". It appears under CreateParams
How do I access these parameters of "sender" in my code?
The caption is the Text.
So you can do for example, for a RadioButton :
System::String^ sText = ((System::Windows::Forms::RadioButton^)sender)->Text;
To identify individual controls, you can also write something like this:
if( sender == radioButton1 )
{
. . .
}
where radioButton1 is the name of control that was entered to (Name) field in Properties window. It is the variable that is associated with control.
It is also possible to determine the type of current control.
It depends on your needs.