D
Dave
I build a very simple program that I put at the end of this post. This
program is just supposed to put a button on the screen and exit the program
when I press the escape button. But pressing the escape button doesn't do
anything if I put the code for the button into the program! infact, pressing
escape only works if you take away the little piece of code:
"this.Controls.Add(this.button1);"!! I was totally confused at why this
happened and would really like to fix it. any ideas? Ps: the code works if
instead of a button, I insert a label. it also doesn't work if I insert a
textbox.
thanks
dave
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Threading;
namespace re
{
public class Form1 : Form
{
private System.Windows.Forms.Button button1;
public Form1()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Location = new System.Drawing.Point(670, 220);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.KeyUp += new KeyEventHandler(OnKeyPress);
this.Controls.Add(this.button1);
}
public void OnKeyPress(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Escape)
Application.Exit();
}
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
}
}
}
program is just supposed to put a button on the screen and exit the program
when I press the escape button. But pressing the escape button doesn't do
anything if I put the code for the button into the program! infact, pressing
escape only works if you take away the little piece of code:
"this.Controls.Add(this.button1);"!! I was totally confused at why this
happened and would really like to fix it. any ideas? Ps: the code works if
instead of a button, I insert a label. it also doesn't work if I insert a
textbox.
thanks
dave
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Threading;
namespace re
{
public class Form1 : Form
{
private System.Windows.Forms.Button button1;
public Form1()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Location = new System.Drawing.Point(670, 220);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.KeyUp += new KeyEventHandler(OnKeyPress);
this.Controls.Add(this.button1);
}
public void OnKeyPress(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Escape)
Application.Exit();
}
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
}
}
}