Claviature and shape application processing
-
When writing some calculator, it is necessary to launch both the button and the keyboard. The processing of correct entry from the keyboard was done with the assistance of
KeyPress
which receives(object sender, KeyPressEventArgs e)
further, depending on the situation, either blocks the incorrect clavicle or fails the right.
For the button, the most logical solution, in my view, was the same treatment.KeyPress
♪ For what purpose the buttons were tied to this processor:private void num_Click(object sender, EventArgs e) { char tmp = ((Button)sender).Text[0]; textBox1_KeyPress((Object)textBox1, new KeyPressEventArgs(tmp)); }
Something goes on. Just theoretical,
KeyPress
receives exactly the same on the entrance as when it comes to entry. I mean, there should be similar treatment. The following occurs (this occurs according to the staggering passage of the programme in the holder):
The program goes safely.KeyPress
, all checks, all right, all correct, but it doesn't print the symbols in the textbox. Of course, some colts with forced entry could be attached (which had been implemented), but it would be interesting to know what was going on and how that could be rectified in a given situation.UPD: It's settled! Thank you all for coming back!
This was a great move.
char tmp = ((Button)sender).Text[0]; textBox1.Focus(); SendKeys.Send(tmp.ToString());
And I think I need to look more closely into theory:
-
For the button, the most logical solution, in my view, was to refer to the same KeyPress.
Windows has a series of system messages in the windows. All mouse motions, buttons, etc. fall in this line. Systemic developments are further transformed into Message-type facilities and transferred to the counter.
All Message can be seen if you inherit Control or its derivatives and redesign the virtual method https://msdn.microsoft.com/ru-ru/library/system.windows.forms.control.wndproc(v=vs.110).aspx ♪
And as in Control.WndProc ' s reference method, there's a code that, based on Message data, causes, for example, the fact that of KeyPress and transmits part of the data from Message.
By the event of KeyPress, you can connect your processor and react to an event. I mean, the challenge of his processor does not affect the systemic course of events.In the system line, you can send systemic events from your code, and thus emulate mice movements, clavicle compression. But that's why we need to use Win API. http://www.pinvoke.net/default.aspx/user32.sendmessage ♪ http://pinvoke.net/default.aspx/user32.mouse_event ♪ http://www.pinvoke.net/default.aspx/user32.keybd_event ♪
There's a SendKeys.Send, which is easier to use instead of keybd_event.