Handling Keyboard Shortcuts

B

BD

How can I duplicate the behavior of the operating system shortcut keys
in my application? For example, my windows form has 5 controls
(textboxes), the operating system will pickup which control has the
focus and handle ctrl-c, ctrl-v, or any other shortcuts. I have the
same shortcuts working in my app, but have not determined how to find
out which control has focus. Would I set up a loop or code for each
control at form level. Any help is greatly appreciated.

BD
 
B

BD

I'm not sure you really understand how keyboard input happens. The OS
isn't doing anything special for control-modified keys. All it does is
make sure that the keyboard input is sent to whatever window has the
current focus, and that window deals with it.

In the case of .NET, each instance of Control has its own window, and when
the Control has focus, that means its window has focus and is receiving
keyboard input. Then it's simply a matter of the Control handling the
input as appropriate.

If you want your own custom control to handle keyboard input, you need to
make sure that your control can receive focus, and is handling the
keyboard input messages. Once you've done that, then if and when your
control actually has the focus, it will automatically receive the keyboard
input, which you can then inspect, looking for special key input such as
Ctrl-C, Ctrl-V, etc.

At no point should you need to worry about which control actually has the
focus. Assuming you've implemented your control properly, it will receive
keyboard input appropriately when it has focus, without any additional
effort from you.

Note that for your control to receive focus, its CanFocus property needs
to return "true" (i.e. set the ControlStyle.Selectable flag with the
SetStyle() method). You should also make sure that your control has some
visible representation that indicates when it has focus, which of course
means handling the focus events (e.g. override OnGotFocus(),
OnLostFocus()) so that you know when your state changes.

Pete

I do agree, I may not understand how keyboard input works, I have only
been learning programming for about the past two years on my own. I
perhaps didn't state my issue correctly. The form does use the
shortcuts but with a twist. This is why I posted the way I did. If
my form has the EDIT menu that has the general items inserted, 'ctrl-
v' will not work. However, if you do 'ctrl-shift-v' the program will
paste from the clipboard. If I remove the EDIT menu, 'ctrl-v' or any
of the other shortcuts will work correctly. That is why I thought the
OS was controlling the shortcut. I have looked on the net for some
time to find an answer or even an example of what I see and have come
up empty. I did try protected override bool ProcessCmdKey(ref Message
msg, Keys keyData), which will make the shortcuts work properly, but I
have to identify which textbox to process. That is why I thought I
needed to find out which control has the focus. Again, thanks for the
fast response to my question and I hope to hear from you about my
follow-up.

BD
 
B

BD

[...] If
my form has the EDIT menu that has the general items inserted, 'ctrl-
v' will not work. However, if you do 'ctrl-shift-v' the program will
paste from the clipboard. If I remove the EDIT menu, 'ctrl-v' or any
of the other shortcuts will work correctly. That is why I thought the
OS was controlling the shortcut.

I guess that depends on your definition of "OS". Based on your
description, it's possible that .NET is somehow treating your "EDIT" menu
as something special. One thing you might want to try is making sure that
the menu has the usual shortcut keys assigned to each item in the menu.

Beyond that, you will probably need to post a concise-but-complete code
sample that reliably demonstrates the problem. You can describe the issue
in plain English until you're blue in the face, but doing so will never
provide nearly as precise or accurate a description of the problem as an
actual working code sample.

Pete

The app I am sending is a testing app that I created for control
testing. I just created it the other day. It has two forms, one form
to tell me the ASCII numbers of the keys I am pressing the main form
which is form1. Form1 is very simple with only two textboxes and two
labels. Textbox1 is a multi-line textbox. I used the standard menu
inserted by Visual Studio 2005 (file, edit, tools, help). The
following is the code I have from Form1.cs:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TestingApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

protected override bool ProcessCmdKey(ref Message msg, Keys
keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;

if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
switch (keyData)
{
case (Keys.V | Keys.Control):
textBox1.Text = Clipboard.GetText();
return true;
break;

case (Keys.C | Keys.Control):
if (textBox1.SelectedText != "")

Clipboard.SetDataObject(textBox1.SelectedText);
else
MessageBox.Show("There is no data to copy
to the clipboard.");
return true;
break;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}

private void undoToolStripMenuItem_Click(object sender,
EventArgs e)
{
textBox1.Undo();
}

private void selectAllToolStripMenuItem_Click(object sender,
EventArgs e)
{
textBox1.SelectionStart = 0;
textBox1.SelectionLength = textBox1.TextLength;
}

private void editToolStripMenuItem_Click(object sender,
EventArgs e)
{
if (textBox1.SelectionLength == 0)
{
cutToolStripMenuItem.Enabled = false;
copyToolStripMenuItem.Enabled = false;
}
}

private void button1_Click(object sender, EventArgs e)
{
KeyCode frm = new KeyCode();
frm.Show();
frm.Focus();
}

If the designer code is needed, I will send it as well. Again, when
the 'edit' menu is there, shortcut keys for copy and paste for example
require the key combination 'ctrl+shift+c' or 'ctrl+shift+v'.
However, if the edit menu is removed, 'ctrl+c' or 'ctrl+v' work as
they are should.

BD
 
B

BD

[...]
If the designer code is needed, I will send it as well. Again, when
the 'edit' menu is there, shortcut keys for copy and paste for example
require the key combination 'ctrl+shift+c' or 'ctrl+shift+v'.
However, if the edit menu is removed, 'ctrl+c' or 'ctrl+v' work as
they are should.

Inasmuch as your question seems to be specifically related to the exact
configuration of the menus, you should either create the menus
programmatically in the Form1 class, or you should post the complete
Designer code for the test application.

Pete

Here is the designer code:
namespace TestingApplication
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should
be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources =
new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.statusStrip1 = new
System.Windows.Forms.StatusStrip();
this.toolStripStatusLabel1 = new
System.Windows.Forms.ToolStripStatusLabel();
this.toolStripProgressBar1 = new
System.Windows.Forms.ToolStripProgressBar();
this.fileToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.newToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.openToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator = new
System.Windows.Forms.ToolStripSeparator();
this.saveToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.saveAsToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new
System.Windows.Forms.ToolStripSeparator();
this.printToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.printPreviewToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new
System.Windows.Forms.ToolStripSeparator();
this.exitToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolsToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.customizeToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.optionsToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.helpToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.contentsToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.indexToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.searchToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator5 = new
System.Windows.Forms.ToolStripSeparator();
this.aboutToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.editToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.undoToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.redoToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator3 = new
System.Windows.Forms.ToolStripSeparator();
this.cutToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.copyToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.pasteToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator4 = new
System.Windows.Forms.ToolStripSeparator();
this.selectAllToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.button1 = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(16, 36);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(66, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Sample Text";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(16, 196);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(35, 13);
this.label2.TabIndex = 2;
this.label2.Text = "label2";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(16, 262);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(35, 13);
this.label3.TabIndex = 3;
this.label3.Text = "label3";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(16, 302);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(35, 13);
this.label4.TabIndex = 4;
this.label4.Text = "label4";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(16, 347);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(35, 13);
this.label5.TabIndex = 5;
this.label5.Text = "label5";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(88, 36);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(341, 146);
this.textBox1.TabIndex = 6;
this.textBox1.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);
this.textBox1.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(88,
193);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 7;
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabel1,
this.toolStripProgressBar1});
this.statusStrip1.Location = new System.Drawing.Point(0,
414);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(855, 22);
this.statusStrip1.TabIndex = 8;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusLabel1
//
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new
System.Drawing.Size(740, 17);
this.toolStripStatusLabel1.Spring = true;
this.toolStripStatusLabel1.Text = "toolStripStatusLabel1";
//
// toolStripProgressBar1
//
this.toolStripProgressBar1.Name = "toolStripProgressBar1";
this.toolStripProgressBar1.Size = new
System.Drawing.Size(100, 16);
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.newToolStripMenuItem,
this.openToolStripMenuItem,
this.toolStripSeparator,
this.saveToolStripMenuItem,
this.saveAsToolStripMenuItem,
this.toolStripSeparator1,
this.printToolStripMenuItem,
this.printPreviewToolStripMenuItem,
this.toolStripSeparator2,
this.exitToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new
System.Drawing.Size(35, 20);
this.fileToolStripMenuItem.Text = "&File";
//
// newToolStripMenuItem
//
this.newToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("newToolStripMenuItem.Image")));
this.newToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.newToolStripMenuItem.Name = "newToolStripMenuItem";
this.newToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.N)));
this.newToolStripMenuItem.Size = new
System.Drawing.Size(151, 22);
this.newToolStripMenuItem.Text = "&New";
//
// openToolStripMenuItem
//
this.openToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("openToolStripMenuItem.Image")));
this.openToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.O)));
this.openToolStripMenuItem.Size = new
System.Drawing.Size(151, 22);
this.openToolStripMenuItem.Text = "&Open";
//
// toolStripSeparator
//
this.toolStripSeparator.Name = "toolStripSeparator";
this.toolStripSeparator.Size = new
System.Drawing.Size(148, 6);
//
// saveToolStripMenuItem
//
this.saveToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("saveToolStripMenuItem.Image")));
this.saveToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.saveToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.S)));
this.saveToolStripMenuItem.Size = new
System.Drawing.Size(151, 22);
this.saveToolStripMenuItem.Text = "&Save";
//
// saveAsToolStripMenuItem
//
this.saveAsToolStripMenuItem.Name =
"saveAsToolStripMenuItem";
this.saveAsToolStripMenuItem.Size = new
System.Drawing.Size(151, 22);
this.saveAsToolStripMenuItem.Text = "Save &As";
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new
System.Drawing.Size(148, 6);
//
// printToolStripMenuItem
//
this.printToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("printToolStripMenuItem.Image")));
this.printToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.printToolStripMenuItem.Name =
"printToolStripMenuItem";
this.printToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.P)));
this.printToolStripMenuItem.Size = new
System.Drawing.Size(151, 22);
this.printToolStripMenuItem.Text = "&Print";
//
// printPreviewToolStripMenuItem
//
this.printPreviewToolStripMenuItem.Image =
((System.Drawing.Image)
(resources.GetObject("printPreviewToolStripMenuItem.Image")));
this.printPreviewToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.printPreviewToolStripMenuItem.Name =
"printPreviewToolStripMenuItem";
this.printPreviewToolStripMenuItem.Size = new
System.Drawing.Size(151, 22);
this.printPreviewToolStripMenuItem.Text = "Print
Pre&view";
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new
System.Drawing.Size(148, 6);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new
System.Drawing.Size(151, 22);
this.exitToolStripMenuItem.Text = "E&xit";
//
// toolsToolStripMenuItem
//
this.toolsToolStripMenuItem.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.customizeToolStripMenuItem,
this.optionsToolStripMenuItem});
this.toolsToolStripMenuItem.Name =
"toolsToolStripMenuItem";
this.toolsToolStripMenuItem.Size = new
System.Drawing.Size(44, 20);
this.toolsToolStripMenuItem.Text = "&Tools";
//
// customizeToolStripMenuItem
//
this.customizeToolStripMenuItem.Name =
"customizeToolStripMenuItem";
this.customizeToolStripMenuItem.Size = new
System.Drawing.Size(134, 22);
this.customizeToolStripMenuItem.Text = "&Customize";
//
// optionsToolStripMenuItem
//
this.optionsToolStripMenuItem.Name =
"optionsToolStripMenuItem";
this.optionsToolStripMenuItem.Size = new
System.Drawing.Size(134, 22);
this.optionsToolStripMenuItem.Text = "&Options";
//
// helpToolStripMenuItem
//
this.helpToolStripMenuItem.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.contentsToolStripMenuItem,
this.indexToolStripMenuItem,
this.searchToolStripMenuItem,
this.toolStripSeparator5,
this.aboutToolStripMenuItem});
this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
this.helpToolStripMenuItem.Size = new
System.Drawing.Size(40, 20);
this.helpToolStripMenuItem.Text = "&Help";
//
// contentsToolStripMenuItem
//
this.contentsToolStripMenuItem.Name =
"contentsToolStripMenuItem";
this.contentsToolStripMenuItem.Size = new
System.Drawing.Size(129, 22);
this.contentsToolStripMenuItem.Text = "&Contents";
//
// indexToolStripMenuItem
//
this.indexToolStripMenuItem.Name =
"indexToolStripMenuItem";
this.indexToolStripMenuItem.Size = new
System.Drawing.Size(129, 22);
this.indexToolStripMenuItem.Text = "&Index";
//
// searchToolStripMenuItem
//
this.searchToolStripMenuItem.Name =
"searchToolStripMenuItem";
this.searchToolStripMenuItem.Size = new
System.Drawing.Size(129, 22);
this.searchToolStripMenuItem.Text = "&Search";
//
// toolStripSeparator5
//
this.toolStripSeparator5.Name = "toolStripSeparator5";
this.toolStripSeparator5.Size = new
System.Drawing.Size(126, 6);
//
// aboutToolStripMenuItem
//
this.aboutToolStripMenuItem.Name =
"aboutToolStripMenuItem";
this.aboutToolStripMenuItem.Size = new
System.Drawing.Size(129, 22);
this.aboutToolStripMenuItem.Text = "&About...";
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.editToolStripMenuItem,
this.toolsToolStripMenuItem,
this.helpToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(855, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.undoToolStripMenuItem,
this.redoToolStripMenuItem,
this.toolStripSeparator3,
this.cutToolStripMenuItem,
this.copyToolStripMenuItem,
this.pasteToolStripMenuItem,
this.toolStripSeparator4,
this.selectAllToolStripMenuItem});
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new
System.Drawing.Size(37, 20);
this.editToolStripMenuItem.Text = "&Edit";
this.editToolStripMenuItem.Click += new
System.EventHandler(this.editToolStripMenuItem_Click);
//
// undoToolStripMenuItem
//
this.undoToolStripMenuItem.Name = "undoToolStripMenuItem";
this.undoToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.Z)));
this.undoToolStripMenuItem.Size = new
System.Drawing.Size(150, 22);
this.undoToolStripMenuItem.Text = "&Undo";
this.undoToolStripMenuItem.Click += new
System.EventHandler(this.undoToolStripMenuItem_Click);
//
// redoToolStripMenuItem
//
this.redoToolStripMenuItem.Name = "redoToolStripMenuItem";
this.redoToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.Y)));
this.redoToolStripMenuItem.Size = new
System.Drawing.Size(150, 22);
this.redoToolStripMenuItem.Text = "&Redo";
//
// toolStripSeparator3
//
this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new
System.Drawing.Size(147, 6);
//
// cutToolStripMenuItem
//
this.cutToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("cutToolStripMenuItem.Image")));
this.cutToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.cutToolStripMenuItem.Name = "cutToolStripMenuItem";
this.cutToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.X)));
this.cutToolStripMenuItem.Size = new
System.Drawing.Size(150, 22);
this.cutToolStripMenuItem.Text = "Cu&t";
//
// copyToolStripMenuItem
//
this.copyToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("copyToolStripMenuItem.Image")));
this.copyToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.copyToolStripMenuItem.Name = "copyToolStripMenuItem";
this.copyToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.C)));
this.copyToolStripMenuItem.Size = new
System.Drawing.Size(167, 22);
this.copyToolStripMenuItem.Text = "&Copy";
this.copyToolStripMenuItem.Click += new
System.EventHandler(this.copyToolStripMenuItem_Click);
//
// pasteToolStripMenuItem
//
this.pasteToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("pasteToolStripMenuItem.Image")));
this.pasteToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.pasteToolStripMenuItem.Name =
"pasteToolStripMenuItem";
this.pasteToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.V)));
this.pasteToolStripMenuItem.Size = new
System.Drawing.Size(150, 22);
this.pasteToolStripMenuItem.Text = "&Paste";
//
// toolStripSeparator4
//
this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new
System.Drawing.Size(147, 6);
//
// selectAllToolStripMenuItem
//
this.selectAllToolStripMenuItem.Name =
"selectAllToolStripMenuItem";
this.selectAllToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.A)));
this.selectAllToolStripMenuItem.Size = new
System.Drawing.Size(167, 22);
this.selectAllToolStripMenuItem.Text = "Select &All";
this.selectAllToolStripMenuItem.Click += new
System.EventHandler(this.selectAllToolStripMenuItem_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(590,
287);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(152, 23);
this.button1.TabIndex = 9;
this.button1.Text = "Key Code Info Form";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new
System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F,
13F);
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(855, 436);
this.Controls.Add(this.button1);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form1";
this.Text = "Form1";
this.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);
this.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel
toolStripStatusLabel1;
private System.Windows.Forms.ToolStripProgressBar
toolStripProgressBar1;
private System.Windows.Forms.ToolStripMenuItem
fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
newToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
openToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator
toolStripSeparator;
private System.Windows.Forms.ToolStripMenuItem
saveToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
saveAsToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator
toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem
printToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
printPreviewToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator
toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem
exitToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
toolsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
customizeToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
optionsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
helpToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
contentsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
indexToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
searchToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator
toolStripSeparator5;
private System.Windows.Forms.ToolStripMenuItem
aboutToolStripMenuItem;
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem
editToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
undoToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
redoToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator
toolStripSeparator3;
private System.Windows.Forms.ToolStripMenuItem
cutToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
copyToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
pasteToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator
toolStripSeparator4;
private System.Windows.Forms.ToolStripMenuItem
selectAllToolStripMenuItem;
private System.Windows.Forms.Button button1;
}
}
 
B

BD

No, absolutely it wouldn't be. It's not a question of whether the
application is compiled or not, and in fact a person would really need the
source code for an example in order to examine what's going on. You
should provide something they can compile but which contains nothing that
would distract from the fundamental issue, and you should provide it in
this newsgroup.

I have no idea whether I can even answer your question. All I can do at
the moment is explain to you the steps you'll need to take if you're going
to get anyone to help, whether that person happens to be me or not.

I'm happy to make an effort, time permitting, but only if you can present
the question in the best way. It's my opinion that between my own
comments and Jon's article, there is ample information here to help you
construct a suitable code sample. Now it's up to you to do that.

Pete

Sorry, I made a typo. Of course, a compiled version would be
useless. I do apologize for not conveying my problem correctly. I
created a new program with one form, one label, and one textbox. I
inserted a menu strip the standard items inserted by VS 05. When I am
in the program, copy and paste function with the following keyboard
keys pressed "ctlr+shift+c" and "ctlr+shift+v". Now, if I remove the
menu from the program, copy and paste works with the following
keyboard keys pressed "ctlr+c" and "ctrl+v". The code below is what
is produced by VS 05 by duplicating what I did above.

Program.cs

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace QuestionApp
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QuestionApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

For1.Designer.cs

namespace QuestionApp
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should
be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources =
new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.newToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.openToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator = new
System.Windows.Forms.ToolStripSeparator();
this.saveToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.saveAsToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new
System.Windows.Forms.ToolStripSeparator();
this.printToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.printPreviewToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new
System.Windows.Forms.ToolStripSeparator();
this.exitToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.undoToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.redoToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator3 = new
System.Windows.Forms.ToolStripSeparator();
this.cutToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.copyToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.pasteToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator4 = new
System.Windows.Forms.ToolStripSeparator();
this.selectAllToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolsToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.customizeToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.optionsToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.helpToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.contentsToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.indexToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.searchToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator5 = new
System.Windows.Forms.ToolStripSeparator();
this.aboutToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(115,
31);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(180, 47);
this.textBox1.TabIndex = 0;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(17, 34);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(92, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Enter Text to Test";
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.editToolStripMenuItem,
this.toolsToolStripMenuItem,
this.helpToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(307, 24);
this.menuStrip1.TabIndex = 2;
this.menuStrip1.Text = "menuStrip1";
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.newToolStripMenuItem,
this.openToolStripMenuItem,
this.toolStripSeparator,
this.saveToolStripMenuItem,
this.saveAsToolStripMenuItem,
this.toolStripSeparator1,
this.printToolStripMenuItem,
this.printPreviewToolStripMenuItem,
this.toolStripSeparator2,
this.exitToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new
System.Drawing.Size(35, 20);
this.fileToolStripMenuItem.Text = "&File";
//
// newToolStripMenuItem
//
this.newToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("newToolStripMenuItem.Image")));
this.newToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.newToolStripMenuItem.Name = "newToolStripMenuItem";
this.newToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.N)));
this.newToolStripMenuItem.Size = new
System.Drawing.Size(32, 19);
this.newToolStripMenuItem.Text = "&New";
//
// openToolStripMenuItem
//
this.openToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("openToolStripMenuItem.Image")));
this.openToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.O)));
this.openToolStripMenuItem.Size = new
System.Drawing.Size(32, 19);
this.openToolStripMenuItem.Text = "&Open";
//
// toolStripSeparator
//
this.toolStripSeparator.Name = "toolStripSeparator";
this.toolStripSeparator.Size = new System.Drawing.Size(6,
6);
//
// saveToolStripMenuItem
//
this.saveToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("saveToolStripMenuItem.Image")));
this.saveToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.saveToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.S)));
this.saveToolStripMenuItem.Size = new
System.Drawing.Size(32, 19);
this.saveToolStripMenuItem.Text = "&Save";
//
// saveAsToolStripMenuItem
//
this.saveAsToolStripMenuItem.Name =
"saveAsToolStripMenuItem";
this.saveAsToolStripMenuItem.Size = new
System.Drawing.Size(32, 19);
this.saveAsToolStripMenuItem.Text = "Save &As";
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(6,
6);
//
// printToolStripMenuItem
//
this.printToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("printToolStripMenuItem.Image")));
this.printToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.printToolStripMenuItem.Name =
"printToolStripMenuItem";
this.printToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.P)));
this.printToolStripMenuItem.Size = new
System.Drawing.Size(32, 19);
this.printToolStripMenuItem.Text = "&Print";
//
// printPreviewToolStripMenuItem
//
this.printPreviewToolStripMenuItem.Image =
((System.Drawing.Image)
(resources.GetObject("printPreviewToolStripMenuItem.Image")));
this.printPreviewToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.printPreviewToolStripMenuItem.Name =
"printPreviewToolStripMenuItem";
this.printPreviewToolStripMenuItem.Size = new
System.Drawing.Size(32, 19);
this.printPreviewToolStripMenuItem.Text = "Print
Pre&view";
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(6,
6);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new
System.Drawing.Size(32, 19);
this.exitToolStripMenuItem.Text = "E&xit";
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.undoToolStripMenuItem,
this.redoToolStripMenuItem,
this.toolStripSeparator3,
this.cutToolStripMenuItem,
this.copyToolStripMenuItem,
this.pasteToolStripMenuItem,
this.toolStripSeparator4,
this.selectAllToolStripMenuItem});
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new
System.Drawing.Size(37, 20);
this.editToolStripMenuItem.Text = "&Edit";
//
// undoToolStripMenuItem
//
this.undoToolStripMenuItem.Name = "undoToolStripMenuItem";
this.undoToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.Z)));
this.undoToolStripMenuItem.Size = new
System.Drawing.Size(152, 22);
this.undoToolStripMenuItem.Text = "&Undo";
//
// redoToolStripMenuItem
//
this.redoToolStripMenuItem.Name = "redoToolStripMenuItem";
this.redoToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.Y)));
this.redoToolStripMenuItem.Size = new
System.Drawing.Size(152, 22);
this.redoToolStripMenuItem.Text = "&Redo";
//
// toolStripSeparator3
//
this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new
System.Drawing.Size(149, 6);
//
// cutToolStripMenuItem
//
this.cutToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("cutToolStripMenuItem.Image")));
this.cutToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.cutToolStripMenuItem.Name = "cutToolStripMenuItem";
this.cutToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.X)));
this.cutToolStripMenuItem.Size = new
System.Drawing.Size(152, 22);
this.cutToolStripMenuItem.Text = "Cu&t";
//
// copyToolStripMenuItem
//
this.copyToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("copyToolStripMenuItem.Image")));
this.copyToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.copyToolStripMenuItem.Name = "copyToolStripMenuItem";
this.copyToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.C)));
this.copyToolStripMenuItem.Size = new
System.Drawing.Size(152, 22);
this.copyToolStripMenuItem.Text = "&Copy";
//
// pasteToolStripMenuItem
//
this.pasteToolStripMenuItem.Image = ((System.Drawing.Image)
(resources.GetObject("pasteToolStripMenuItem.Image")));
this.pasteToolStripMenuItem.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.pasteToolStripMenuItem.Name =
"pasteToolStripMenuItem";
this.pasteToolStripMenuItem.ShortcutKeys =
((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |
System.Windows.Forms.Keys.V)));
this.pasteToolStripMenuItem.Size = new
System.Drawing.Size(152, 22);
this.pasteToolStripMenuItem.Text = "&Paste";
//
// toolStripSeparator4
//
this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new
System.Drawing.Size(149, 6);
//
// selectAllToolStripMenuItem
//
this.selectAllToolStripMenuItem.Name =
"selectAllToolStripMenuItem";
this.selectAllToolStripMenuItem.Size = new
System.Drawing.Size(152, 22);
this.selectAllToolStripMenuItem.Text = "Select &All";
//
// toolsToolStripMenuItem
//
this.toolsToolStripMenuItem.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.customizeToolStripMenuItem,
this.optionsToolStripMenuItem});
this.toolsToolStripMenuItem.Name =
"toolsToolStripMenuItem";
this.toolsToolStripMenuItem.Size = new
System.Drawing.Size(44, 20);
this.toolsToolStripMenuItem.Text = "&Tools";
//
// customizeToolStripMenuItem
//
this.customizeToolStripMenuItem.Name =
"customizeToolStripMenuItem";
this.customizeToolStripMenuItem.Size = new
System.Drawing.Size(32, 19);
this.customizeToolStripMenuItem.Text = "&Customize";
//
// optionsToolStripMenuItem
//
this.optionsToolStripMenuItem.Name =
"optionsToolStripMenuItem";
this.optionsToolStripMenuItem.Size = new
System.Drawing.Size(32, 19);
this.optionsToolStripMenuItem.Text = "&Options";
//
// helpToolStripMenuItem
//
this.helpToolStripMenuItem.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.contentsToolStripMenuItem,
this.indexToolStripMenuItem,
this.searchToolStripMenuItem,
this.toolStripSeparator5,
this.aboutToolStripMenuItem});
this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
this.helpToolStripMenuItem.Size = new
System.Drawing.Size(40, 20);
this.helpToolStripMenuItem.Text = "&Help";
//
// contentsToolStripMenuItem
//
this.contentsToolStripMenuItem.Name =
"contentsToolStripMenuItem";
this.contentsToolStripMenuItem.Size = new
System.Drawing.Size(32, 19);
this.contentsToolStripMenuItem.Text = "&Contents";
//
// indexToolStripMenuItem
//
this.indexToolStripMenuItem.Name =
"indexToolStripMenuItem";
this.indexToolStripMenuItem.Size = new
System.Drawing.Size(32, 19);
this.indexToolStripMenuItem.Text = "&Index";
//
// searchToolStripMenuItem
//
this.searchToolStripMenuItem.Name =
"searchToolStripMenuItem";
this.searchToolStripMenuItem.Size = new
System.Drawing.Size(32, 19);
this.searchToolStripMenuItem.Text = "&Search";
//
// toolStripSeparator5
//
this.toolStripSeparator5.Name = "toolStripSeparator5";
this.toolStripSeparator5.Size = new System.Drawing.Size(6,
6);
//
// aboutToolStripMenuItem
//
this.aboutToolStripMenuItem.Name =
"aboutToolStripMenuItem";
this.aboutToolStripMenuItem.Size = new
System.Drawing.Size(32, 19);
this.aboutToolStripMenuItem.Text = "&About...";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F,
13F);
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(307, 85);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form1";
this.Text = "Form1";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem
fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
newToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
openToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator
toolStripSeparator;
private System.Windows.Forms.ToolStripMenuItem
saveToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
saveAsToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator
toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem
printToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
printPreviewToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator
toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem
exitToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
editToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
undoToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
redoToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator
toolStripSeparator3;
private System.Windows.Forms.ToolStripMenuItem
cutToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
copyToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
pasteToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator
toolStripSeparator4;
private System.Windows.Forms.ToolStripMenuItem
selectAllToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
toolsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
customizeToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
optionsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
helpToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
contentsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
indexToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem
searchToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator
toolStripSeparator5;
private System.Windows.Forms.ToolStripMenuItem
aboutToolStripMenuItem;
}
}

The above is the program.cs, the form1.cs, and the form1.designer.cs.
Again, I do want to thank you for sharing your knowledge with me so
far.

BD
 
B

BD

[...] The code below is what
is produced by VS 05 by duplicating what I did above.

I don't think so.

I tried, really. In spite of the fact that the code you posted still had
all sorts of menu items that I seriously doubt have anything to do with
the problem, I went ahead and made a project using the code.

However, I still couldn't get it to run, because you've referenced a
resource ("newToolStripMenuItem.Image") that of course doesn't exist in my
project.

I'm sorry. I am serious when I mean you need to post simple code. The
harder you make others work in order to try to answer your question, the
less likely it is you're going to get an answer at all. You really need
to put some effort into it. This means literally making the posted code
as brief as is possible while still being a complete program, and still
reproducing the issue.

You still haven't done that. I probably could fiddle with the code you
posted and get something that works, but a) then I would not be sure that
I'm using the exact code you're using, and b) it's really just more
trouble than I care to put into the question. I'm sorry if that seems
selfish of me, but sometimes that's just how it goes.

Pete

To be honest with you, I don't what else I can do. I let VS 05 do the
code writing for me. That is where the reference came in. I did not
write a single bit of the code. VS did all of the code writing. I
have yet to find an answer to this question in any of my research. I
suppose I will take out the menus completely, that solves the problem
with the 'shift' key. I would love to see any example of a simple
form with the menus intact so I can see how they are coded. I run
many different pieces of software that all have the menus that VS put
in the program for me. They work correctly in them. Thanks for the
help, but as you said, this has turned out to be more trouble for me
than it is worth. I will teach my users the Windows XP keyboard
shortcuts.
 
J

John

Hi BD,

You need to write code in order to make a toolstripmenuitem
do something when the user presses the assigned shortcut
(Ctrl+C, Ctrl+V, etc.), or if they choose the menu with the
mouse.

For example, if you select the Copy menu in the designer,
double-click, and then enter code like this:

private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
TextBox tb = this.ActiveControl as TextBox;
if (tb != null)
{
tb.Copy();
};
}

One thing that is confusing you is that the TextBox has
some built-in functionality that works by default. For example,
if a user presses Ctrl+C or Ctrl+Shift+C or Ctrl+Ins or
chooses Copy from the context menu it will Copy. If you
add a menu with Ctrl+C set as the shortcut, the TextBox
will not receive Ctrl+C, hence the default code will not
run. Ctrl+Shift+C or Ctrl+Ins will still trigger the default code
since you have not defined menus with those shortcuts.

One approach you may choose to use is to add event handler
code for Application.Idle and enable/disable various commands
as appropriate. This will have the effect of enabling/disabling
things like Cut, Copy, Paste in realtime as the user navigates
the form. For example, if no text is selected or if the current
control is a button the Copy menu would be disabled.

For winforms-related questions it is more appropriate to post
in microsoft.public.dotnet.framework.windowsforms first.

Thanks.

J
 
B

BD

Hi BD,

You need to write code in order to make a toolstripmenuitem
do something when the user presses the assigned shortcut
(Ctrl+C, Ctrl+V, etc.), or if they choose the menu with the
mouse.

For example, if you select the Copy menu in the designer,
double-click, and then enter code like this:

private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
TextBox tb = this.ActiveControl as TextBox;
if (tb != null)
{
tb.Copy();
};

}

One thing that is confusing you is that the TextBox has
some built-in functionality that works by default. For example,
if a user presses Ctrl+C or Ctrl+Shift+C or Ctrl+Ins or
chooses Copy from the context menu it will Copy. If you
add a menu with Ctrl+C set as the shortcut, the TextBox
will not receive Ctrl+C, hence the default code will not
run. Ctrl+Shift+C or Ctrl+Ins will still trigger the default code
since you have not defined menus with those shortcuts.

One approach you may choose to use is to add event handler
code for Application.Idle and enable/disable various commands
as appropriate. This will have the effect of enabling/disabling
things like Cut, Copy, Paste in realtime as the user navigates
the form. For example, if no text is selected or if the current
control is a button the Copy menu would be disabled.

For winforms-related questions it is more appropriate to post
in microsoft.public.dotnet.framework.windowsforms first.

Thanks.

J

Thank you John, I was really having trouble locating this in a google
search. Everything I was finding was telling me keypress and/or
keydown events to handle this. I was unaware of the built in events
and therefore thought it was the OS that was handling the events. The
example code you posted makes sense, it just never showed up in my
google searches. I have written a full fledged front-end connecting
with my SQL Server 05 database on remote server, but my users had
questioned me about the keyboard shortcuts. Again, thank you very
much for helping me with my issue, and I will post in the the category
you spoke of first next time.

Sincerely,

BD
 

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