Error when displaying a context menu
To all,
I'm writing this for a custom WinCE 5.0 device. This code was part of a .NET dll that worked fine when compiled in VS 2003. My company is moving to VS 2005 and this problem popped up in a DLL that we've been using for years,
This function is part of a custom NotifyIcon class that we wrote to put an icon in the Windows CE system tray and create a context menu when the user taps the icon. When compiled under VS 2003, everything works fine. When compiled under VS 2005, we get a runtime error when a user taps on the icon. Ive narrowed the error down to:
m_MenuForm.ContextMenu.Show(m_MenuForm,new System.Drawing.Point(0, 0));
Which should show the context menu after user tap. Instead, the program crashes with an error at that point.
So I have two questions:
#1. Is there a new way to put an icon in the system tray and use a context menu in .NET compact Framework 2.0 ?
#2. If there isn't, am I doing anything wrong in this section of code that is causing everything to crash?
Ryan
privatevoid ShowContextMenu()
{
if (m_PopupMenu !=null)
{
int iXpos = 0;
int iYpos = 0;
// Calculate the location of the context menu.
iXpos =
Screen.PrimaryScreen.WorkingArea.Width - CalculateMenuWidth() - 35;iYpos =
Screen.PrimaryScreen.WorkingArea.Height - CalculateMenuHeight() + 10;// Set the location of the form to display the context menu.m_MenuForm.Location =
new System.Drawing.Point(iXpos, iYpos);m_MenuForm.ControlBox =
false;m_MenuForm.FormBorderStyle = System.Windows.Forms.
FormBorderStyle.None;m_MenuForm.Size =
new System.Drawing.Size(1, 1);m_MenuForm.ContextMenu = m_PopupMenu;
m_MenuForm.ContextMenu.Show(m_MenuForm,
new System.Drawing.Point(0, 0));}
}

