As you can see in that screenshot in "objArgs" there is a property "Text". How can I reach that property?
Asked
Active
Viewed 1,113 times
4
-
1Show the method signature – Tim Schmelter Jan 20 '16 at 09:44
-
@Roman the only things I can select after the dot is "Equals", "GetHashCode", "GetType", "SetUnderConstruction" and "ToString" – Bayern Jan 20 '16 at 09:45
-
@Roman hehe ye his answer works! – Bayern Jan 20 '16 at 09:49
-
2Sure, it's Jon Skeet ;) – roemel Jan 20 '16 at 09:49
1 Answers
9
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.

Jon Skeet
- 1,421,763
- 867
- 9,128
- 9,194
-
Yes that's it thank you! I accept this answer in 7 min! It doesn't allow me right now. – Bayern Jan 20 '16 at 09:48