I'm quite new to C# and programming in general. Basically my problem is that I am trying to make a simple code, which uses key input, but when I run (debug) the program, it doesn't recognize any key input at all. KeyPreview is set to true, but it still seems not to do anything. Could you please tell me what am I doing wrong? Thank you.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public List<string> list = new List<string>();
public Form1()
{
InitializeComponent();
KeyPreview = true;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F3)
{
list.Add("OMG!");
}
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(list[0]);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}