wxButton and identifier Topic is solved
wxButton and identifier
How to get the value of wxButton label based on the Identifier or otherwise. I have a few buttons on wxDialog and I would like to bind the event by clicking on any button to display the label of that button.
Re: wxButton and identifier
Hi,
In order to do that you need to write:
Thank you.
In order to do that you need to write:
Code: Select all
MyDialog::MyDialog()
{
auto *button1 = new wxButton(...);
auto *button2 = new wxButton(...);
button1->Bind( wxEVT_BUTTON, &MyDialog::ProcessClick, this );
button2->Bind( wxEVT_BUTTON, &MyDialog::ProcessClick, this );
}
void MyDialog::ProcessClick(wxCommandEvent &event)
{
wxButton buttonClicked = dynamic_cast<wxButton *>( event.GetEventObject() );
if( buttonClicked == button1 )
wxMessageBox( "First button clicked" + buttonClicked->GetLabel() );
else
wxMessageBox( "Second button clicked" + buttonClicked->GetLabel() );
}
Re: wxButton and identifier
Thx but for this
I have error
Code: Select all
wxButton buttonClicked = dynamic_cast<wxButton *>( event.GetEventObject() );
error: conversion from 'wxButton*' to non-scalar type 'wxButton' requested|
Re: wxButton and identifier
The declaration of buttonClicked was missing the asterisk, it should be
Code: Select all
wxButton* buttonClicked = dynamic_cast<wxButton *>( event.GetEventObject() );
Re: wxButton and identifier
Thank you all for your help. What I needed was this:
and works.
Thx @ONEEYEMAN and @PB.
Code: Select all
wxButton* buttonClicked = dynamic_cast<wxButton *>( event.GetEventObject() );
tcPinDisplay->SetValue(buttonClicked->GetLabel());
Thx @ONEEYEMAN and @PB.