Switching menus

  • Thread starter Thread starter Guest
  • Start date Start date
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)
{
}
}
 
There isn't some better approach that I am aware of.

You can remove and re-add menuitems to a menu OR create many menus and swap
them. Rather than swapping/repopulating them at the moment the user wants to
display the menu, consider doing that when the context has changed (the perf
hit should be negligible and I have found that works well).

As for opening menus, try the mouse_event:
http://www.danielmoth.com/Blog/2004/11/mouseevent.html

For more specific help, try including the code you tried and failed
("unusable" and "won't display" without a code example is not very helpful).

Cheers
Daniel
 
Hi Daniel,

1) I can't switch menus when the context change, the context is defined by
the selection in the tree view. Scrolling becomes so slow when switching
menus that way that I had to find another way to do it (I don't have only 2
contexts like in my example, so the menus have to be swapped many times while
scrolling).

2) There's no other code needed to switch the menus in my application. I
didn't include the menu creation but that's about it. I'm sure my problem is
caused by the keybd_event. I'll try to simulate the mouse instead of the
keyboard like you suggested.

Thanks for your time Daniel, it's really appreciated!

Regards,

Sylvain Fortin
 
Hi Daniel,

mouse_event doesn't work on the Smartphone so I still have the same problem.
I didn't check if I could get a return value with GetLastError(), but since
the mouse isn't supported on the Smartphone, it makes sense that it doesn't
work.

Thanks,

Sylvain Fortin
 
Somehow I filtered out the fact that you are using Smartphone as well as
PocketPC...

Cheers
Daniel
 
Back
Top