Is there any mechanism where I can get update notification when users try to open an menu item, like in MFC. I know there is no direct way, but there should be lot of hacks, that's what I am asking.
+2
A:
What architecture?
In winforms (MenuStrip
) you can use the DropDownOpening
event - that do?
On the older MenuItem
, there is the Popup
event that works similarly.
I'm not sure about WPF...
This demonstrates both (MenuItem
first, then ToolStripMenuItem
):
using System;
using System.Windows.Forms;
static class Program {
[STAThread]
static void Main() {
// older menuitem
MenuItem mi;
using (Form form = new Form {
Menu = new MainMenu {
MenuItems = {
(mi = new MenuItem("abc"))
}
}
})
{
mi.MenuItems.Add("dummy");
mi.Popup += delegate {
mi.MenuItems.Clear();
mi.MenuItems.Add(DateTime.Now.ToLongTimeString());
};
Application.Run(form);
}
MenuStrip ms;
ToolStripMenuItem tsmi;
using (Form form = new Form {
MainMenuStrip = (ms = new MenuStrip {
Items = {
(tsmi = new ToolStripMenuItem("def"))
}
})
})
{
form.Controls.Add(ms);
tsmi.DropDownItems.Add("dummy");
tsmi.DropDownOpening += delegate {
tsmi.DropDownItems.Clear();
tsmi.DropDownItems.Add(DateTime.Now.ToLongTimeString());
};
Application.Run(form);
}
}
}
Marc Gravell
2009-02-08 09:21:42
Thanks for the help, it was so easy and I thought there is no way in C#.
Priyank Bolia
2009-02-08 21:37:17