I have a very simple C# WinForm sample:
private System.Windows.Forms.ContextMenuStrip ct1;
var header = new ToolStripMenuItem("Header with long test like Lorem Ipsum");
header.Enabled = false;
var txt = new ToolStripTextBox();
txt.Text = "changeme";
ct1.Items.Clear();
ct1.Items.Add(header);
ct1.Items.Add(txt);
ct1.Show(x,y);
Now I have two issues with this:
How can I ask the textbox to fill the full width of the menu (i.e. be as large as the largest item)?
If I press the
Alt
key, the menu closes. I can prevent it by handling theClosing
event:
Like this:
private void ct1_Closing(object sender, ToolStripDropDownClosingEventArgs e)
{
e.Cancel = (e.CloseReason == ToolStripDropDownCloseReason.Keyboard);
}
However I want to be able to close by pressing Escape, and I also want to be able to use Alt key as input.
But now Alt and Escape are all or nothing. How can I differentiate between them?
Tried even on KeyDown event for the TextBox and also for ct1
, but Alt key is not forwarded to there.