Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. dynamically displaying an image in a menu?

dynamically displaying an image in a menu?

Scheduled Pinned Locked Moved C#
questionhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Megidolaon
    wrote on last edited by
    #1

    I want to display a check mark next to the text of a ToolStripMenuItem, when the user clicked on it. in the form editor I set the ImageAlign property to MiddleLeft, that should display the image on the right side of the text or? But how do I achieve that the image gets displayed only whe the user clicks on the menu item? And whe he does, the image that was displayed for another menu option should be erased (so that the user see which of the options is selected and can see which one he selected)? I tried the Image and ImageList properties, but I got an error: Invalid parameter Thanks.

    D J 2 Replies Last reply
    0
    • M Megidolaon

      I want to display a check mark next to the text of a ToolStripMenuItem, when the user clicked on it. in the form editor I set the ImageAlign property to MiddleLeft, that should display the image on the right side of the text or? But how do I achieve that the image gets displayed only whe the user clicks on the menu item? And whe he does, the image that was displayed for another menu option should be erased (so that the user see which of the options is selected and can see which one he selected)? I tried the Image and ImageList properties, but I got an error: Invalid parameter Thanks.

      D Offline
      D Offline
      Deresen
      wrote on last edited by
      #2

      Well, I don't have my VS in front of me, so I'll do it out of my head. There are several possibility's. I think you should do something like this: In your code, make a function like this:

      String[] imagePaths = {"mypic1.jpg", "mypic2.jpg", "mypic3.jpg"};

      public void clearMenuItemImages()
      {
      mi1.Image = null;
      mi2.Image = null;
      mi3.Image = null;
      }

      public void onMenuItem1Clicked(object sender, EventArgs e)
      {
      clearMenuItemImages();
      ((ToolStripMenuItem)sender).Image = imagePath[0];
      }

      //etc.

      You can make this faster and better, but this is a start.

      1 Reply Last reply
      0
      • M Megidolaon

        I want to display a check mark next to the text of a ToolStripMenuItem, when the user clicked on it. in the form editor I set the ImageAlign property to MiddleLeft, that should display the image on the right side of the text or? But how do I achieve that the image gets displayed only whe the user clicks on the menu item? And whe he does, the image that was displayed for another menu option should be erased (so that the user see which of the options is selected and can see which one he selected)? I tried the Image and ImageList properties, but I got an error: Invalid parameter Thanks.

        J Offline
        J Offline
        Jimmanuel
        wrote on last edited by
        #3

        Images ??? Alignment ??? What ??? ToolStripMenuItems have a Checked Property. Set it to true to display a check mark next to the text, set it to false to make the check mark go away.

        :Badger:

        M 1 Reply Last reply
        0
        • J Jimmanuel

          Images ??? Alignment ??? What ??? ToolStripMenuItems have a Checked Property. Set it to true to display a check mark next to the text, set it to false to make the check mark go away.

          :Badger:

          M Offline
          M Offline
          Megidolaon
          wrote on last edited by
          #4

          Thanks, that did the trick.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups