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

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

enter image description here

Jon Skeet
people
quotationmark

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.

people

See more on this question at Stackoverflow