I want a variable to be incremented when I press the spacebar. This is what I have tried so far, and it doesn't seem to be working. There's no error message, so I don't know what is wrong.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
int Coins = 0;
int ButtonKeyNumber = (int)Key.Space;
private void textBlockCoins_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyValue == ButtonKeyNumber)
{
Coins = Coins + 1;
textBlockCoins.Text = "You Have " + Coins + "Coins";
}
}
}
When I run the code, the textbox just says "You Have 0 Coins". The variable ButtonKeyNumber is there because I want to be able to easily change which key will need to be pressed.