Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the "Text" value out of "System.EventArgs objArgs"

Tags:

c#

eventargs

As you can see in that screenshot in "objArgs" there is a property "Text". How can I reach that property?

enter image description here

like image 518
Bayern Avatar asked Jan 07 '23 19:01

Bayern


1 Answers

You need to cast the args to ToolBarItemEventArgs, at which point you can access the ToolBarButton it refers to:

var toolBarArgs = (ToolBarItemEventArgs) objArgs;
switch (toolBarArgs.ToolBarButton.Text)
{
    ...
}

However, I would suggest not switching on the text. Instead, ideally set up a different event handler for each of your buttons. If you really can't do that, you can use:

var toolBarArgs = (ToolBarItemEventArgs) objArgs;
var button = toolBarArgs.ToolBarButton;
if (button == saveButton)
{
    ...
}

Or you could switch on the Name rather than the Text - I'd expect the Name to be basically an implementation detail, whereas the Text is user-facing and could well be localized.

like image 109
Jon Skeet Avatar answered Jan 19 '23 04:01

Jon Skeet