G
Guest
Hi everyone,
I would like to change my menu items depending on the context of the
selection. I don't want to disable them because they will still be visible.
By the way, my application is written for Smartphone and PocketPC using C#. I
wish I could use MenuItem.Visible = false and PerformClick() but they're not
available! Also, I can't clear the MenuItem array because the object becomes
unusable, so instead of having to create the menu over and over again, I
created many different menus.
The only solution I found is to switch the menu at the moment the user wants
to display (event Popup). The problem is that the menu wont display anymore,
so I simulate the click on the menu by sending F2 to the application using
keybd_event().
Problem: This solution works most of the time but I need something better
than that. Sometimes the menu won't even open, the next time it will open and
close immediately. I need a solution and any help will be greatly appreciated.
Thanks,
Sylvain Fortin
Here is my code:
private void m_mnuMain_ItemMenu_Popup(object sender, EventArgs e)
{
try
{
if (Context1)
{
if (!((Form)Parent).Menu.Equals(m_mnuContext1Main))
{
((Form)Parent).Menu = m_mnuContext1Main;
MyUtils.keybd_event(0x71, 0, 0x0001, 0);
MyUtils.keybd_event(0x71, 0, 0x0001 | 0x0002,0);
}
}
else
{
if (!((Form)Parent).Menu.Equals(m_mnuContext2Main))
{
((Form)Parent).Menu = m_mnuContext2Main;
MyUtils.keybd_event(0x71, 0, 0x0001, 0);
MyUtils.keybd_event(0x71, 0, 0x0001 | 0x0002,0);
}
}
}
catch (Exception)
{
}
}
I would like to change my menu items depending on the context of the
selection. I don't want to disable them because they will still be visible.
By the way, my application is written for Smartphone and PocketPC using C#. I
wish I could use MenuItem.Visible = false and PerformClick() but they're not
available! Also, I can't clear the MenuItem array because the object becomes
unusable, so instead of having to create the menu over and over again, I
created many different menus.
The only solution I found is to switch the menu at the moment the user wants
to display (event Popup). The problem is that the menu wont display anymore,
so I simulate the click on the menu by sending F2 to the application using
keybd_event().
Problem: This solution works most of the time but I need something better
than that. Sometimes the menu won't even open, the next time it will open and
close immediately. I need a solution and any help will be greatly appreciated.
Thanks,
Sylvain Fortin
Here is my code:
private void m_mnuMain_ItemMenu_Popup(object sender, EventArgs e)
{
try
{
if (Context1)
{
if (!((Form)Parent).Menu.Equals(m_mnuContext1Main))
{
((Form)Parent).Menu = m_mnuContext1Main;
MyUtils.keybd_event(0x71, 0, 0x0001, 0);
MyUtils.keybd_event(0x71, 0, 0x0001 | 0x0002,0);
}
}
else
{
if (!((Form)Parent).Menu.Equals(m_mnuContext2Main))
{
((Form)Parent).Menu = m_mnuContext2Main;
MyUtils.keybd_event(0x71, 0, 0x0001, 0);
MyUtils.keybd_event(0x71, 0, 0x0001 | 0x0002,0);
}
}
}
catch (Exception)
{
}
}