Menu shortcut ignored in readonly control

A

Andrus

If focused control is ReadOnly, menu shortcut key is ignored.

To reproduce, run code below, press Ctrl+E.
Note that message box does not appear.

This issue blocks Ctrl+E usage in application.
How to fix ?

Andrus.


using System;
using System.Windows.Forms;

static class Program
{
static void Main()
{
Application.Run(new Form1());
}
}

class Form1 : Form
{
public Form1()
{
menuStrip1 = new MenuStrip();
fileToolStripMenuItem = new ToolStripMenuItem();
openToolStripMenuItem = new ToolStripMenuItem();
textBox1 = new TextBox();
menuStrip1.Items.AddRange(new ToolStripItem[] {
fileToolStripMenuItem });
fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] {
openToolStripMenuItem });
fileToolStripMenuItem.Text = "File";
openToolStripMenuItem.ShortcutKeys = ((Keys)((Keys.Control |
Keys.E)));
openToolStripMenuItem.Text = "Open";
openToolStripMenuItem.Click += new
System.EventHandler(openToolStripMenuItem_Click);
textBox1.Location = new System.Drawing.Point(55, 150);
textBox1.ReadOnly = true;
Controls.Add(textBox1);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
}

void openToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Clicked");
}

MenuStrip menuStrip1;
ToolStripMenuItem fileToolStripMenuItem;
ToolStripMenuItem openToolStripMenuItem;
TextBox textBox1;
}
 
J

Jeff Winn

Seems to be limited to the Ctrl key as a modifier. I switched the key
modifier to Alt and had no problems with it. If you must use the Ctrl key as
the modifier, you could make the control mimic a readonly control without
actually setting the ReadOnly property.
 
A

Andrus

Jeff,
Seems to be limited to the Ctrl key as a modifier. I switched the key
modifier to Alt and had no problems with it. If you must use the Ctrl key
as the modifier, you could make the control mimic a readonly control
without actually setting the ReadOnly property.

Thank you.
I have various controls in form contained in single UserControl: TextBox,
CombBobox, DateTimebox, RichTextBox,CheckBox.

As I understand only way to make Ctel+E to work is to implement custor
readonly/disabled property for all of them ?

If those controls are inside gid, Ctrl+E works.
Ctrl+K works in all cases, this seems to related to Ctrl+E only.
Maybe I can use my container control, UserControl to fix this ?
I tried also to set MDI child and parent formKeyPreview to true but this
does not fix this.

Is this net bug ?
Should I post this issue to MS Product Feedback ?

Andrus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top