 |
|
 |
Thank you for your hard work !
|
|
|
|
 |
|
 |
some menus is builded dynamic, can this component use for dynamic menu? thanks!
|
|
|
|
 |
|
 |
i used MenuEx, but a contextmenu for notifyicon connt show normorly.
|
|
|
|
 |
|
 |
I'm afraid that .NET doesn't seem to support owner-draw for context menus linked to a NotifyIcon, so never triggers the appropriate events. I've tried to find a solution before but been unsuccessful. To prevent MenuEx from trying to draw the MenuItems belonging to the relevant context menu, simply set the ImageIndex for each MenuItem to -2.
Hope that helps,
Jonathan
|
|
|
|
 |
|
|
 |
|
 |
Is it able to run on VS 2003. I try it on VS 2003, but it not able to run. However it suceed to rebuild.
Any idea?
Himadrish Laha
|
|
|
|
 |
|
 |
Hello,
I'm not sure what you mean - the solution and project were all written in VS 2003, so there should be no problem. Can you be more specific about the problem in running it?
Best Regards,
Jonathan
|
|
|
|
 |
|
 |
Hi,
I use your component in my apps form.
Then, on the form I have "OnPaint" event to refresh an image.
What happened was the event occurs a lot and causing the image blinking.
I suspected that it is caused from your component.
Is that true, or my misunderstanding?
|
|
|
|
 |
|
 |
Hello,
I don't think the "image blinking" is caused by MenuEx - the only time MenuEx causes any extra painting is when you resize a form, as it has to refresh the "Menu Bar". If you like you can send me a small example showing the problem and I will take a look,
Best Regards,
Jonathan
|
|
|
|
 |
|
 |
Hi,
I'm using this in a project for a client and I'm running into a bit of a cosmetic issue.
In my application, I have two user controls which expose a menu to a parent form. When each of the controls becomes active, their menus are merged with the main menu.
On startup, the form's menu and the active control gets merged properly and the menu bar is drawn fully in a nice shade of blue. When my 2nd form becomes visible, I recreate the main menu using CloneMenu and MergeMenu:
In Form.cs:
private void viewPage_Activated(object sender, EventArgs e)
{
MainMenu newMenu = this.managerMainMenu.CloneMenu();
if (complaintPage.Active && complaintPage.Menu != null)
{
newMenu.MergeMenu(complaintPage.Menu);
}
if (compilationPage.Active && compilationPage.Menu != null)
{
newMenu.MergeMenu(compilationPage.Menu);
}
this.Menu = newMenu;
}
When my 2nd user control is now visible, it has a grey menu background from the last top menu item to the right edge of the form. Each of the menu's on the controls has a menupainter and menuex instance.
Any clues as to how I can get this working?
|
|
|
|
 |
|
 |
Any chance you could send me a small sample which shows this problem? I'm sure there will be a way around it but am deep in code at the moment, so it would help if I didn't have to create a test case myself,
Cheers,
Jonathan
|
|
|
|
 |
|
 |
I'll see what I can do. I too am deep in code at the moment but I'll see if I can send something out tonight.
Cheers,
Zedd
|
|
|
|
 |
|
 |
Zedd,
OK, this turned out to be somewhat more difficult than I first thought, but I think I've found a solution.
Firstly, you need to add the following public method to the MenuEx component:
public void Recreate(MainMenu mnu) {
if (mnu != null) {
mainMenu = mnu;
if (mainMenu != null) {
form = mainMenu.GetForm();
if (form != null) {
if (menuPainter != null) {
RecreateBitmap();
}
}
}
}
}
You can call this after merging the menus and it will force the recreation of the bitmap used for drawing the menu bar, thus getting rid of your 'grey' area.
However, I found that when I tested the code you sent, any merging of the menus caused the existing menu items to lose their association with the MenuEx component - therefore any images associated with the items were being lost.
To get around this, I used a slightly different approach. Instead of merging the new menu into the original (main) menu, I did it the other way round. So, to add items from the first 'new' merge menu I did this:
private MenuItem AddItem(Menu.MenuItemCollection items, string text, int imageIndex, EventHandler clickEvent) {
MenuItem item = null;
if (items != null) {
item = new MenuItem(MenuMerge.MergeItems, 0, Shortcut.None, text, clickEvent, null, null, null);
menuEx1.SetImageIndex(item, imageIndex);
items.Add(item);
}
return item;
}
private MainMenu CreateFirstMergeMenu() {
MainMenu result = new MainMenu();
MenuItem topItem = AddItem(result.MenuItems, "First", -1, new EventHandler(ClickMe));
AddItem(topItem.MenuItems, "First Sub-item 1", 1, new EventHandler(ClickMe));
AddItem(topItem.MenuItems, "First Sub-item 2", 2, new EventHandler(ClickMe)); return result;
}
private void btnMerge_Click(object sender, System.EventArgs e) {
MainMenu mnuFirst = CreateFirstMergeMenu();
mnuFirst.MergeMenu(mainMenu1);
this.Menu = mnuFirst;
menuEx1.Recreate(this.Menu);
}
Then, creating a second merge menu works in exactly the same way:
private MainMenu CreateSecondMergeMenu() {
MainMenu result = new MainMenu();
MenuItem topItem = AddItem(result.MenuItems, "Second", -1, new EventHandler(ClickMe));
AddItem(topItem.MenuItems, "Second Sub-item 1", 3, new EventHandler(ClickMe));
AddItem(topItem.MenuItems, "Second Sub-item 2", 4, new EventHandler(ClickMe)); return result;
}
private void btnMergeSecond_Click(object sender, System.EventArgs e) {
MainMenu mnuSecond = CreateSecondMergeMenu();
mnuSecond.MergeMenu(mainMenu1);
this.Menu = mnuSecond;
menuEx1.Recreate(this.Menu);
}
Finally, to return to the original menu:
private void btnMerge_Click(object sender, System.EventArgs e) {
MainMenu mnuFirst = CreateFirstMergeMenu();
mnuFirst.MergeMenu(mainMenu1);
this.Menu = mnuFirst;
menuEx1.Recreate(this.Menu);
}
I will send you a zip-file with a working example of the above. I hope this solves your problem, if not, please let me know,
All the best,
Jonathan
|
|
|
|
 |
|
 |
Thanks Jonathan,
It's working well.
Zedd
|
|
|
|
 |
|
 |
I found an interesting article here.
private static void ProtectFromDrawing(Graphics g,Rectangle rect)
{
IntPtr hdc = g.GetHdc();
try
{
ExcludeClipRect (hdc,
rect.Left,
rect.Top,
rect.Right,
rect.Bottom);
}
finally
{
g.ReleaseHdc(hdc);
}
}
[DllImport("Gdi32.dll")]
public static extern int ExcludeClipRect(
IntPtr hdc, // handle to DC
int nLeftRect, // x-coord of upper-left corner
int nTopRect, // y-coord of upper-left corner
int nRightRect, // x-coord of lower-right corner
int nBottomRect // y-coord of lower-right corner
);
Perhaps that will let you customize the sub-item arrows as you see fit.
|
|
|
|
 |
|
 |
Very nice control. Exactly what I was looking for.
I found one thing that doesn't seem to work right: when I change my menu at runtime (you can switch language), it is not recreated. The Problem is, that menuItems have different width in different languages. If I change language I get some menuItems with too much free space.
Any idea how to fix this?
Florian
|
|
|
|
 |
|
 |
Florian,
Nothing instantly occurs to me - I will try it out early next week and see if I can find the problem,
Cheers,
Jonathan
|
|
|
|
 |
|
 |
Jonathan,
Thanks. Try this:
Create a menu which contains a menuitem with a long text. E.g. the MenuItem that's usually "File". Then change it's text-property at runtime to a short text. If there are MenuItems on the right side of this MenuItem, you will see what I mean.
Here some ASCII-"Art" to illustrate (ignore dots):
------------------ -------------
| a long text here ||another icon |
------------------ -------------
>> change text
------------------ -------------
| short.............. ||another icon |
------------------ -------------
Florian
|
|
|
|
 |
|
 |
Just writing to thank you for MenuEx, and to say I believe I fixed a
memory leak in your component. To see how it is leaking, just
resize (and keep resizing) your demo application and check the memory
utilisation in Task Manager.
Anyway, this is the corrected 'SetBrush' method in MenuEx.cs. I am
not a 100% that the first two statements are really needed. The
main problem was that the bitmap being returned by
'GetHbitmap' was not being deallocated.
private void SetBrush() {
if (BarBrush != IntPtr.Zero)
SafeNativeMethods.DeleteObject(BarBrush);
IntPtr ibmp = barBitmap.GetHbitmap();
BarBrush = SafeNativeMethods.CreatePatternBrush(ibmp);
MENUINFO mi = new MENUINFO(form);
mi.fMask = MIM_BACKGROUND;
mi.hbrBack = BarBrush;
SafeNativeMethods.SetMenuInfo(mainMenu.Handle, ref mi);
SafeNativeMethods.SendMessage(form.Handle, WM_NCPAINT, 0, 0);
SafeNativeMethods.DeleteObject(ibmp);
}
Regards
Rubens
|
|
|
|
 |
|
 |
This stuff is VERY nice. Thank you for sharing it.
I have a problem though which is that 32 bit PNG images do not have their transparency displayed correctly. I have the colour depth of the ImageList set to Depth32Bit and there's nothing to do.
Strangely enough when I try a GIF image with just a simple 1 bit transparent layer (ImageList.ColorDepth = Depth24Bit), it works OK.
I don't think this bug but someone may have some ideas as to why this is happening. This is on WinXP btw.
Thanks
|
|
|
|
 |
|
 |
Not sure myself why this is happening, though I suspect that the fault may lie with the .NET framework. I will do some experiments and let you know how I get on,
Best Regards,
Jonathan
|
|
|
|
 |
|
 |
I think you're right. I've been looking around and this business of broken transparencies in 32 bit images seems to be quite common within the framework. Haven't found a satisfactory explanation for it though.
Anything you find will be of great interest. Thanks
Bahman
|
|
|
|
 |
|
 |
You can get 32-bit transparency to work with a few lines of code.
Look for your "Application.Run" statement and add "Application.EnableVisualStyles();" and "Application.DoEvents();" right before it.
I think the transparency problem is due to a bug with the ImageList, but I'm not 100% sure.
|
|
|
|
 |
|
 |
Thanks for the tip, but I already have that in place and it has no effect. The strange thing is that the transparency problem occurs only with the menus and not with for example toolbar buttons. I've looked at the menuEx code and can't see why it shouldn't work.
Re: bug with ImageList, I've also seen references to that elsewehere but that did not help either.
If/When I work out what's doing it, I'll post my findings.
|
|
|
|
 |
|
 |
Hallo Sir,
While I have developed an MDI app using your control. It is no doubt good. But when I open any mdi child (which also has the same MenuEx control as its parent) the part of the menubar in the parent form looses its color (color specified by the menupainter control). The most interesting thing is that menubar looses its color after the last entry in the mainmenu.
What should I do now?
Please help me in this concern. Thank you in advance.
Anindya Chatterjee
|
|
|
|
 |