Hello guys. I created an Windows Forms Application template, and on my Form I attached a Label. I activated the KeyPress event for my Form, and when I press any key ( letter, number ), it adds that key to the label1. But when I attached a button on my Form, and I open the application and I press any key, nothing happens. Follow my screenshots please:
- my simple form before to press any Key: http://img211.imageshack.us/img211/1312/firstform.png
- my simple form after I press 5 keys (h,e,l,l,o): http://img14.imageshack.us/img14/2299/2ndform.png
- my simple form with a button on it: http://img32.imageshack.us/img32/9040/buttonadded.png
And here is the code source:
- my simple form before to press any Key: http://img211.imageshack.us/img211/1312/firstform.png
- my simple form after I press 5 keys (h,e,l,l,o): http://img14.imageshack.us/img14/2299/2ndform.png
- my simple form with a button on it: http://img32.imageshack.us/img32/9040/buttonadded.png
And here is the code source:
using System; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_KeyPress(object sender, KeyPressEventArgs e) { label1.Text += e.KeyChar; } } }