Disable MenuStrip Dropdown in Windows Forms Application - winforms

I am disabling the parent menu option in a Windows forms menustrip. When you hover over it, the submenu still opens. Is there a way to disable the submenu opening or do I have to disable all the submenu items?

Having the menu drop down show on mouse hover does not seem to be the default behavior of a ToolStripMenuItem and I could not find a property to enable this.
I did find this post by someone who wanted this behavior, and you should check to see if there is a MouseHover event handler for the ToolStripMenuItem and check the Enabled property there:
private void toolStripMenuItem1_MouseHover(object sender, EventArgs e)
{
if (toolStripMenuItem1.Enabled)
toolStripMenuItem1.DropDown.Show(menuStrip1, new Point(0, 0));
}
HTH

Just set the Enableproperty on the parent menu to False. In .net 2.0 and 3.5 the submenu will not show.
Also please try to be a little more specific.

I ended up looping through the DropDownItems and disabling them after I disable the main item.
for (int i = 0; i < this._menuOpen.DropDownItems.Count; i++)
{
this.menuOpen.DropDownItems[i].Enabled = false;
}

Related

Devexpress Popup menu with GridControl Popup menu

Where I Right-Click on GridColumn To Popup the GridColumn Menu
It Pops up with the main Popup menu
Your problem appears to be caused by PopupMenu being called all over regardless of the location of the mouse.
Use event "PopupMenuShowing" to display the user menu in GridControl. You can implement this event to decide whether to display pop-ups based on the location of your mouse.
private void gridview1_PopupMenuShowing(object sender, PoupMenuShowingEventArgs e)
{
// check in row and in cell
if(!e.HitInfo.InRow && !e.HitInfo.InRowCell)
return;
// showing main(user) popup menu
popupMenu1.ShowPopup(gridcontrol1.PointToScreen(new Point(e.Point.X, e.Point.Y)));
}

Prevent drop-down menu to close

I have a big problem. I want to prevent an opened drop-down menu to close when hovering another menu item. How can I achieve this? Thanks.
Regards
Marius
You should have a look at the event that's called when you are hovering another item, probably LostFocusor LostMouseCapture, look at the function called aith this event (OnLostFocus or OnLostMouseCapture) and override this method like this :
public override void OnLostFocus()
{
base.OnLostFocus();
Popup popup = Template.FindName("PART_Popup", this) as Popup;
popup.IsOpen = true;
}
This way, the event won't close the drop down menu. (The example above is for a combobox)
I'm not sure about the right event to override. It depends on your problem. You can find the list of event here if these are not the right ones. But I think that's the way you should do it.

Adding items to below gridview when dropped on top gridview

On my main page, I have a button and telerik mainRadGridView. When I click my button, I get a popup which is divided it into two regions left and right.
On left, I have a RadTreeView and on right, I have a popupRadGridView.
Initially when my popup is open, the popupRadGridView is disabled. When I drop from left to right for first time in my popup nothing is added to popupRadGridView since it is disable which is correct.
But when I drop for second time on to my disabled popupRadGridView inside my opened popup, there is an element added to my mainRadGridView on my main page which is wrong.
I cannot understand how to stop adding onto my main page. Any help is greatly appreciated.
check for the e.Options.ParticipatingVisualRoots in Drop Event of GridView - should provide you the no of active opened child windows participating in the operation.
For additional information follow this link
Telerik Silverlight
I solved my issue as below
In my mainpage codebehind. I did like below
void mainRadGridView_OnDropInfo(object sender, DragDropEventArgs e)
{
if(e.Options.ParticipatingVisualRoots.Count > 0)
{
return;
}
else
{
do stuff;
}
}

Systray context menu - why are my commands not enabled?

I'm creating a WPF app and have a system tray icon with a context menu. For the menu items I want to use WPF commands but when I assign them they are always greyed out even though the (same) commands are enabled in other places.
MenuItem menuItem = new MenuItem();
menuItem.Header = "Exit";
menuItem.Command = CustomCommands.ExitApplication;
Systray.AddMenuItem(menuItem);
It works fine when I assign click events and I have tried to create a CanExecute method for the command which always sets CanExecute to true, but that doesn't help either. Anyone got an idea why the menu items are disabled?
Update: As suggested, I added a command binding to the context menu. This had the effect that it works but only after you have clicked on the menu, i.e., at first the menu items are greyed out but once you click somewhere on the menu the options become enabled.
To solve this problem I called the following, after I added the menu items to the context menu:
CommandManager.InvalidateRequerySuggested();
Of the top of my head I'd guess you have to add a CommandBinding to the Menu or systray so that your command gets handled. Although I think if that were the case it would be enabled by default.
Yea I've seen this occur. Sometimes you have to tell the WPF CommandManager system to rerun the CanExecute methods. Try calling this once the ContextMenu is loaded: CommandManager.InvalidateQuerySuggested();
I had a similar issue. I feel my solution it's a bit of a hack, but I could really not get around this problem. I'm using a custom DelegateCommand implementation, and ebabling/disabling buttons and menu items works except for items in context menus. So, what I did was to handle the ContextMenuOpening event, then store the Items in a temp variable, call the Clear method in the ContextMenu and re-add the items right after. Works like a charm, but like I said, feels "hacky". It goes something like this:
private void ContextMenu_ContextMenuOpening (object sender, System.ComponentModel.CancelEventArgs e)
{
// HACK: For some reason items need to be removed and added back so that the command enablement requery works.
var menu = sender as ContextMenu;
if (menu == null) return;
var menuItems = menu.Items.ToArray();
menu.Items.Clear();
foreach (var menuItem in menuItems)
menu.Items.Add(menuItem);
}

How do I disable the exit button on a Silverlight 3 Child Window?

I mean the small exit/cancel button marked with an X in the top right hand corner. I want to implement a Logon dialog box that accepts a username/password so obviously I don't want the user to be able to dismiss the modal pop up. If it is not possible to remove or disable the button then is there some way I can intercept the closing event and stop it closing?
You can use the HasCloseButton property of the ChildWindow to hide the close button.
Please let me know if this helps.
Ezequiel Jadib
The code below prevents a ChildWindow from ever closing, effectively disabling the X button. Modify to suit your business logic.
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
base.OnClosing(e);
e.Cancel = true;
}
Select child window and Press F4. It will show the property window. Then goto HasCloseButton property and uncheck the checkbox.
Enjoy
HasCloseButton="False" ..
This property used to hide the 'X' button In ChildWindow

Resources