VS 2008 and context menus

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




I have a class which includes a context menu. The class, and context menu, appears to work fine when I run the application but when
I look at the designer for the class I get the errors :

The variable renameSwatchMenuItem is either undeclared or was never assigned.
The variable deleteSwatchMenuItem is either undeclared or was never assigned.

Any ideas of how I can track the problem down would be welcome. The following is the relevant code


Thanks,
Steve

....
protected System.Windows.Forms.ContextMenu meContextMenu;
protected MenuItem renameSwatchMenuItem;
protected MenuItem deleteSwatchMenuItem;
protected bool meContextMenuEnabled = true;

....

protected SwatchPanel()
{
InitializeComponent();

this.meContextMenuEnabled = true;
EnableContextMenu(false);


}

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.meColorTip = new System.Windows.Forms.ToolTip(this.components);
this.deleteSwatchMenuItem = new System.Windows.Forms.MenuItem("Delete Swatch", new EventHandler(this.m_contextMenu_Popup));
this.renameSwatchMenuItem = new System.Windows.Forms.MenuItem("Rename Swatch", new EventHandler(this.m_contextMenu_Popup));
this.SuspendLayout();

this.meColorTip.Active = false;

this.meContextMenu = new ContextMenu(new System.Windows.Forms.MenuItem[] { this.deleteSwatchMenuItem,
this.renameSwatchMenuItem});
this.meContextMenu.Popup += new System.EventHandler(this.m_contextMenu_Popup);

this.ContextMenu = this.meContextMenu;
this.ResumeLayout(false);
}


private void m_contextMenu_Popup(object sender, System.EventArgs e)
{
MenuItem miClicked = null;

if (sender is MenuItem)
miClicked = (MenuItem)sender;
else
return;

string item = miClicked.Text;

switch (item)
{
case "Delete Swatch" : DeleteSwatch(this.meRightClickPoint);
break;

case "Rename Swatch" : RenameSwatch(this.meRightClickPoint);
break;

}


}

internal void EnableContextMenu(bool enable)
{
if (enable)
{
if (!this.meContextMenuEnabled)
{
this.meContextMenu.Popup += new System.EventHandler(this.m_contextMenu_Popup);
this.meContextMenuEnabled = true;
}
}
else
{
if (this.meContextMenuEnabled)
{
this.meContextMenu.Popup -= new System.EventHandler(this.m_contextMenu_Popup);
this.meContextMenuEnabled = false;
}
}
}
.



Relevant Pages

  • Showing a context menu during drag and drop
    ... I'm trying to show a context menu during a drag drop operation similar to the windows explorers right click drag and drop behavior: ... void treeView1_DragDrop(object sender, DragEventArgs e) ... private void OnCmClick ... but the OnCmClick handler of the context menu is executed *after* the drag and drop has finished. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Newbie Q: How to determine WHICH item was clicked on context menu
    ... private void contextMenuStrip1_MouseClick(object sender, ... MouseEventArgs e) ... items that are found on my Context Menu that the User clicked. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: DataGridView Row Context Menu
    ... >the context menu based on different location the user right clicked the ... Sample code like this: ... >private void dataGridView1_MouseDown(object sender, MouseEventArgs e) ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Simple context menu problem
    ... > What's wrong with the context menu? ... > I have created one for the DataGrid control and showing it like this: ... > private void dataGrid_MouseUp(object sender, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Rational for not making cursor tagged in Containers
    ... With the traditionally abstract OO, operations are executed as a result ... i.e. ones marshaled and ones referenced (recipients). ... This adds additional asymmetry, c, the sender is invisible and actually is ... the sender's context, which is even not a value. ...
    (comp.lang.ada)