I've run into this strange behaviour so maybe someone has an idea as to why
it occurs... Here are the quick repro steps please bear with me.
1. To a CE winforms project add 2 forms
2. Set their window state to maximised
3. Add a context menu with 1 menu item to the first form
4. In the menu item click event handler create the second form and show it
5. Add a button to the first form that does a ContextMenu1.Show(...)
Run the project. You should get form 1 displayed full screen. Clicking on
the button shows the contextmenu. Clicking on the menuitem in the context
menu shows the second form fullscreen. Closing the second form brings us
back to the first form. OK.
Now, what we really want is to show the contextmenu when a treenode is
selected. So working with the previous code:
6. Add a treeview with a couple of nodes
7. In the AfterSelect event handler show the context menu (as we did
previously for button_click)
Run the project. Click on a treenode to show the contextmenu. Click on the
menuitem and there: The second form is just about to be displayed when form1
retains the focus (and the second form is opened up behind it). Why?
The workaround of toggling visibility of the master form is not applicable
in my real application for a number of reasons.
The other way I worked around it (although I'd still like to hear your
opinions on this) follows:
In the AfterSelect handler use the ThreadPool.QueueUserWorkItem to pass
control to a private method on the form. In the private method use Invoke to
pass control to another private method. In the latter private method show
the contextmenu. It now works as expected. Why?
Cheers
Daniel
Looks like you found a bug here, but I happen to have a simplier workaround
for you...
In the afterselect event show the context menu.
In the menu-selected event, set a flag.
In the got-focus event of the treeview, if the flag is set then show the
2nd form (and clear the flag).
Hope that helps,
-Katie
--------------------
| From: "Daniel Moth" <dmo...@hotmail.com>
| Subject: ContextMenu.Show from TreeView.AfterSelect
| Date: Fri, 6 Jun 2003 12:05:46 +0100
| Lines: 40
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <u5i6awBL...@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 194.242.149.2
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:25013
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks for acknowledging this...it helps...
I am looking for a simpler workaround but I don't think your suggestion
works because the tree may already have the focus (so the user is just
switching between nodes and in fact the treeview is the only control on that
form) so the GotFocus only fires once. Also I would need a flag per menuitem
(as various menuitems show different forms) and another flag to indicate
whether the contextmenu was shown in AfterSelect or by clicking on the
toolbarbutton (with which it is associated).
Looking forward to the bug getting fixed...
Cheers
Daniel
"Katie Schaeffer [MSFT]" <kat...@online.microsoft.com> wrote in message
news:mgaNpJuL...@cpmsftngxa06.phx.gbl...