473,387 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VS 2008 and context menus


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;
}
}
}
Jun 30 '08 #1
1 1288

as soon as I moved all the MenuItem and EventHandler assignments from InitializeComponent the errors disappeared.

Thanks anyway,
Steve

On Mon, 30 Jun 2008 18:33:04 -0400, steve <s_******@yahoo.comwrote:
>
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;
}
}
}
Jul 1 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Doug Bell | last post by:
Hi, If I modify my Registry adding a new key HKEY_CLASSES_ROOT\*\shell\Use My App\command with a (Default) Value of C:\Program Files\Doug\DotNetApps\MyApp.exe "%1" then right clicking on files in...
1
by: Doug Bell | last post by:
Hi, If I modify my Registry adding a new key HKEY_CLASSES_ROOT\*\shell\Use My App\command with a (Default) Value of C:\Program Files\Doug\DotNetApps\MyApp.exe "%1" then right clicking on files in...
1
by: Doug Bell | last post by:
Hi, If I modify my Registry adding a new key HKEY_CLASSES_ROOT\*\shell\Use My App\command with a (Default) Value of C:\Program Files\Doug\DotNetApps\MyApp.exe "%1" then right clicking on files in...
37
by: Prisoner at War | last post by:
Actually, it doesn't have to be a blockquote...but I'm at my wits' end: I want to make bold several lines of text which have a pair of <br /tags between them...seems like the <b></bdo not "carry...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.