NavigationPane ContextMenu

Navigation for Windows Forms Forum

Posted 17 years ago by YB - Sweden
Version: 2.0.93
Avatar
Hi,

I want add an own contextmenu when rightclicking on the NavigationBar buttons.
I have a NavigationBar consisting of NavigationPane:s. Each NavigationPane has a control added to it with a contextmenu, works fine.

However, how can I add the context menu when rightclicking in NavigationBar button? Right now the built in contextmenu is shown with the option: Navigation Bar Options...

I have tried with:

_navigationBar.ContextMenu = contextMenu;

Thanks..
YB

Comments (9)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Since a context menu is generally pretty dynamic, there is a NavigationBar.ContextMenuRequested event that fires when a context menu needs to be displayed.

In this case, you can either choose to do nothing (based on the event args parameters) and this will display the default menu you see. Or you can set e.Cancel and display your own.


Actipro Software Support

Posted 17 years ago by YB - Sweden
Avatar
Thank you,

That does work, however the NavigationBar.ContextMenuRequested event only fires every other time I right click an NavigationBar button? I don't have any clues of why that is. Do you have any idea? Thanks..

/YB
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hmm, I'm not seeing that happen. If you load up our sample project you will see ContextMenuRequested events firing for each right-click on a button.

Perhaps your menu is doing something to capture the mouse in your scenario so the second click is causing the capture to be lost. Or if you still have a ContextMenu property set on NavigationBar, remove that and see if it helps.


Actipro Software Support

Posted 17 years ago by YB - Sweden
Avatar
The only thing I do in this eventhandler is enabling/disabling the context menuitems.

I do have a contextmenu all the time. The context menu is shown everytime I right click, but the event is fired every other time. I can see this when I "debug" and have a breakpoint in this event.
I appreciate suggestions and am trying to solve this meanwhile. The sample that you mentioned works for me as well..

/YB
Posted 17 years ago by YB - Sweden
Avatar
It seems like the event fires slightly delayed, e.g:

1. Right click on the navigationBar - no event fired
2. Click on anything to change focus (could be clicking on another window or anything) - event fires.


hmmm??
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Can you clarify more... are you saying that you still do have a ContextMenu or ContextMenuStrip set to the NavigationBar controls? Or are you saying the "default" menu we show is popping up and you don't have a ContextMenu or ContextMenuStrip set to the NavigationBar controls?


Actipro Software Support

Posted 17 years ago by YB - Sweden
Avatar
Yes, I have a contextmenu (my own) all the time set to the NavigationBar controls, but the problem is that the event is fired after rightclick+"another action", not when only rightclicking.

1. Right click -> context menu is shown (all context menuitems enabled because my code is not run yet obviously.)
2. click somewhere else -> the event is fired (where I enable/disable context menuitems)

It should be as I understand the other way around:

1. right click -> event fired (my code run)
2. context menu shown with correct states on context menuitems

Hope you understand my explanation :)

Thanks
/YB

[Modified at 09/24/2007 02:19 PM]
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks for the info... we've made some modifications for the next maintenance release where the default context menu will not display if you have set one to the NavigationBar and also, the ContextMenuRequested event will fire before the core WM_CONTEXTMENU API message is processed by the control. This way you can change your assigned menu before it is displayed.


Actipro Software Support

Posted 17 years ago by YB - Sweden
Avatar
Ok, thank you.

I have solved it byt handling the MouseDown event for NavigationBar and from there calling the ContextMenuRequested event:

if (e.Button == MouseButtons.Right && e.Clicks == 1)
{
System.Drawing.Point point = new System.Drawing.Point(e.X, e.Y);
BaseNavigationPane navigationPane = (BaseNavigationPane)_navigationBar.HitTest(point);

_navigationBar_ContextMenuRequested(sender,
new NavigationBarContextMenuEventArgs(navigationPane, new System.Drawing.Rectangle(e.Location, new System.Drawing.Size(e.X, e.Y)), new NavigationBarContextMenuSource()));
}
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.