locked
close button in a context menu RRS feed

  • Question

  • hi,

    below an image:

     

    http://imageshack.us/photo/my-images/689/screenshotlx.jpg/

     

    I use a simple context menu to navigate from one window to another in a mdi application.

     

    The context menu is populated and refreshed every time, if the user closes a window or open a new.

     

    I would like to add a close "X" button too to each context menu element.

     

    How is it possible? I have a small "X" button gif. Can I use this?

     

    I think, I should ovveride the onpaint event of the context menu and put this image on the right corner, right?

     

     

    Monday, October 31, 2011 7:39 PM

Answers

  • Hi DerStauner.  Stanav has given you an answer to your question already.  Those images in the picture reflect a built-in functionality to the ContextManuStrip class by way of the Image property.  You can set this in code or through the designer itself in teh PropertyGrid.  You might want to try adding the image to your project's Resources collection and then setting the image property from there.  To do this go to the VS menu and choose Project > (you project name) Properties > Resources tab and then drop down the "Add Resource" to choose "Add Existing File".  This will allow you to browse to an image file (check to be sure the dialog filter is set to image types if you don't see them at first).  You may want to use a .PNG file if there is any tranparency involved (your image example is a red circle with offset "X" - this will require transparency outside those elements). 

    If you were not aware, Visual Studio optionally includes an image library during install that would be found in the following folder:  C:\Program Files\Microsoft Visual Studio <version # here>\Common7\VS2010ImageLibrary\1033.  There you'll find a zip file that you can extract to somewhere in your system.  These images are free for use and you'll find a stock close button image there if you do not already have one (see ~\VS2010ImageLibrary\Actions\32bitcolor bitmaps\16x16 for a stock bitmap close icon - but be aware that it does not have transparency).

     If you do not see these folders then I suggest you run the VS setup again in maintenance mode and check off that feature for re-install.

    • Marked as answer by DerStauner Saturday, November 5, 2011 8:11 PM
    Wednesday, November 2, 2011 2:41 AM

All replies

  • Do you mean the ContextMenuStrip control? If so, you simply set the Image property of the ToolStripMenuItem control for your exit menu item.
    • Proposed as answer by Dig-Boy Wednesday, November 2, 2011 2:41 AM
    Monday, October 31, 2011 7:53 PM
  • please take a look at the linked image. I added a sample "x" button with ms paint. This is the way I imagine it.

     

    I would like to add to each menu item a "x" button on the right corner.

    Tuesday, November 1, 2011 12:47 PM
  • I can't view your image from the link. It's blocked by my company firewall :(
    Tuesday, November 1, 2011 1:51 PM
  • Hi DerStauner.  Stanav has given you an answer to your question already.  Those images in the picture reflect a built-in functionality to the ContextManuStrip class by way of the Image property.  You can set this in code or through the designer itself in teh PropertyGrid.  You might want to try adding the image to your project's Resources collection and then setting the image property from there.  To do this go to the VS menu and choose Project > (you project name) Properties > Resources tab and then drop down the "Add Resource" to choose "Add Existing File".  This will allow you to browse to an image file (check to be sure the dialog filter is set to image types if you don't see them at first).  You may want to use a .PNG file if there is any tranparency involved (your image example is a red circle with offset "X" - this will require transparency outside those elements). 

    If you were not aware, Visual Studio optionally includes an image library during install that would be found in the following folder:  C:\Program Files\Microsoft Visual Studio <version # here>\Common7\VS2010ImageLibrary\1033.  There you'll find a zip file that you can extract to somewhere in your system.  These images are free for use and you'll find a stock close button image there if you do not already have one (see ~\VS2010ImageLibrary\Actions\32bitcolor bitmaps\16x16 for a stock bitmap close icon - but be aware that it does not have transparency).

     If you do not see these folders then I suggest you run the VS setup again in maintenance mode and check off that feature for re-install.

    • Marked as answer by DerStauner Saturday, November 5, 2011 8:11 PM
    Wednesday, November 2, 2011 2:41 AM