[C#] having a long menu not taking all the screen height

Hi,

I display a lot of images in a context menu, using OwnerDraw=true and overring OnMeasureItem/OnDrawItem. The automatically displayed arrows are great, but the menu takes all the screen height! My boss want the menu to be shorter...

I tried to display only a few images, and added my own arrow items at the beginning and the end of them, but I can't make the menu scroll when I click/select the arrows!

- when clicking the arrows, the menu automatically closes
- when selecting them, I dynamically modify the images items, but I can't make the menu update!
I tried everything: Refresh/Update/Invalidate of the parent control, PerformSelect on all the images items, calling SendMessage with WM_PAINT, WM_PRINT, WM_PRINT_CLIENT with the menu handle, and the parent control handle, I've even tried to set to false then back to true all the images items OwnerDraw, they update more or less, but the false ownerdraw menu (brief) displaying is awful!

I didn't manage to find an answer to my problems on the web, so if someone have a clue it would be great to tell me! Either about how making my long menu not taking all the screen height, or forcing the menu to update when I dynamically modify it!

Thanks a lot!
Thibaud



Answer this question

[C#] having a long menu not taking all the screen height

  • mizd

    I found the answer in a French forum:
    http://www.csharpfr.com/code.aspx ID=34929

    The solution consists in using the SetMenuInfo API to set the maximum menu height! But you also need to create a new contextmenu class, as SetMenuInfo needs a handle, and the only valid handle can be obtained by calling CreateMenuhandle, which is a ContextMenu protected method!

  • Hari Krishna Dara

    Why can't you just set the MaximumSize property of the context menu to an appropriate value that limits it's height and adds scrollbars automatically for you if needed
  • Patrick D

    Thanks for your answer Mattias, I indeed forgot about that! Itried it, it works fine except when I have a very large number of images to display:
    - the menu then takes all the screen width, which doesn't look nice
    - if there aren't enough columns to display all the images, there's no way to scroll the missing images, no arrow appear for this!

    But thanks anyway


  • gidon

    >The automatically displayed arrows are great, but the menu takes all the screen height! My boss want the menu to be shorter...

    Have you considered creating a multi-column menu by inserting items with the Break (or BarBreak) property set to true



  • [C#] having a long menu not taking all the screen height