A Question about good Design (.NET, System.Windows.Form.Button, C#)
I was wondering about a smart way to solve the following scenario:
I want to implement an onscreen keyboard with System.Windows.Form
. There are a lot of buttons functions to implement and I don't really want to write a callback function for every single button, since t开发者_开发知识库hey basically all do the same.
Where do I store the 'character' information in the button object, in a solid way, without using too much of a hack?
Or.. generally, can you show me some better approaches to this?
The Tag property of the Button is a good place to store information.
Control.Tag Property via MSDN
Inherit from Button
such that you can provide (probably in the constructor) the character code that the button represents. Use that button.
Alternatively, since the button will show it's character in the button text, just get the button text to find out what has been pressed.
There are a number of on screen keyboards out there for WPF already, might want to take a look at those. If you don't want to use them directly, they may at least point you in a direction:
http://wosk.codeplex.com/
http://wpfkb.codeplex.com/
精彩评论