I have a Windows.Form where I override the OnKeyDown
override protected void OnKeyDown(KeyEventArgs e) {
// do things on specific key presses
}
This works all fine, until I add my Button
class MyWinForm : Form {
static System.Windows.Forms.Timer Timer = new System.Windows.Forms.Timer();
static EventHandler EveryTick;
private System.Windows.Forms.Button button1;
public MyWinForm() {
Width = 300;
Height = 300;
Text = "MyWinForm";
this.button1 = new System.Windows.Forms.Button();
this.button1.Text = "Start";
this.button1.Size = new System.Drawing.Size(100,50);
this.button1.Location = new System.Drawing.Point(10, Height -80);
this.button1.Click += new System.EventHandler(ButtonClick);
this.Controls.Add(this.button1);
}
static void Main() {
// Some more stuff is happening here
Application.Run(new MyWinForm());
}
As soon as I add this.Controls.Add(this.button1);
my OnKeyDown doesn't work anymore.