Then, when a key is pressed, look for the key in the dictionary. If it
exists, get the button and then call the PerformClick method.
On Wed, 30 May 2007 13:50:03 -0700, Nicholas Paldino [.NET/C# MVP]
> Why not parse the file and then assign the mappings to a
> Dictionary<string, Button>.
> Then, when a key is pressed, look for the key in the dictionary. If
> exists, get the button and then call the PerformClick method.
And by "get the button", I expect that Nicholas is referring to the fact
that you can look a button (or any control) up by name:
Where the code is in the form containing the button, and the variable
"strButtonName" is a string set to the button's name (presumably the one
you get back from the Dictionary when you look up the key character).
Depending on where the data is actually coming from and how much
validation has already been done, you may need to check the results of the
"Controls[strButtonName]" expression first, to avoid a null reference
exception. It probably makes more sense though to do that validation when
you read the file and create the dictionary, and just not include invalid
control names in the dictionary in the first place (and perhaps display an
error to the user so that they know there are invalid data in the file).