basically i’m trying to let user select a key for a function. We will have only one button,what i am trying to do is when user clicks that button, capture the first button user clicked and write it to buttontext(and use that key in the future). With the current code, when i open the form it updates the text to No Hotkey. And when i click it, it changes the text to Select a hotkey… But after that it doesnt change the text even if i press any button. What am i doing wrong here? (button1.ButtonText is deafult for me so its not button1.Text)
private Keys shortcutKey;
public Menu()
{
InitializeComponent();
}
private void Menu_Load(object sender, EventArgs e)
{
UpdateButtonLabel();
}
private void button1_Click(object sender, EventArgs e)
{
button1.ButtonText = "Select a hotkey...";
button1.Enabled = false;
button1.Focus();
this.KeyDown += Menu_KeyDown;
}
private void Menu_KeyDown(object sender, KeyEventArgs e)
{
shortcutKey = e.KeyCode;
UpdateButtonLabel();
button1.Enabled = true;
this.KeyDown -= Menu_KeyDown;
}
private void UpdateButtonLabel()
{
button1.ButtonText = shortcutKey == Keys.None ? "No hotkey" : shortcutKey.ToString();
}
Changed button.ButtonText to button.Text, it even broke the first changes. tried to remove focusses ex.