Question 1:
I have tried to add ToolStripMenuItem
in ToolStripComboBox
and added the shortcut keys for ToolStripMenuItem
. It is not working. Can you please put me in right way.
ToolStripMenuItem item1 = new ToolStripMenuItem (){Text = "A", ShortcutKeys=Keys.Control | Keys.D0};
ToolStripMenuItem item2 = new ToolStripMenuItem (){Text = "B", ShortcutKeys=Keys.Control | Keys.D1};
toolStripComboBox1.Items.Add(item1);
toolStripComboBox1.Items.Add(item2);
Question 2: If i implement my shortcut using KeyDown event, the event is triggering twice while pressing right alt key. In first trigger, KeyEventArgs providing data of control key. So, unable to get whether pressed key is Alt or Control key. I have used below example code,
Code:
this.KeyPreview = true;
this.KeyDown += Form1_KeyDown;
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if(e.Control)
{
if(e.KeyCode == Keys.D0)
toolStripComboBox1.SelectedIndex = 0;
else if(e.KeyCode == Keys.D1)
toolStripComboBox1.SelectedIndex = 1;
}
}
Thanks in advance.