locked
Connecting a picturebox with a menustrip RRS feed

  • Question

  • Ok so I am making a program and am stuck on this. I have a picture box and what I want to do with it is when you click on the picturebox, I want the menustrip items to show up, like file, edit, and so on. How would I go about doing this. The name of my menu strip is menuStrip1. I added a click event for the picture box which is as follows:

    private void subPictureBox_Click(object sender, EventArgs e)
            {

            }

    What would the code look like?


    Tuesday, November 20, 2012 10:35 PM

Answers

  • private void pictureBox1_Click(object sender, EventArgs e)
            {
                fileToolStripMenuItem.Visible = true;
                editToolStripMenuItem.Visible = true;
                helpToolStripMenuItem.Visible = true;
            }
    
    private void Form1_Load(object sender, EventArgs e)
            {
                fileToolStripMenuItem.Visible = false;
                editToolStripMenuItem.Visible = false;
                helpToolStripMenuItem.Visible = false;
            }
    Something like this =D

    • Proposed as answer by Jason Dot Wang Thursday, November 22, 2012 7:20 AM
    • Marked as answer by Jason Dot Wang Wednesday, November 28, 2012 9:12 AM
    Tuesday, November 20, 2012 11:52 PM

All replies

  • Hi,

    I'm not quite sure i understand what your goals are, but you can make use of the 'visible' property.

    Set the visible property of the menustrip to false at the start of your application (menuStrip1.Visible = false;),

    and write the following code in your click event: menuStrip1.Visible = true;

    Hope this helped you out ;)

    Tuesday, November 20, 2012 10:45 PM
  • Add a ContextMenuStrip to your form,fill it in and add code to handle clicking on its items.  Set the PictureBox's ContextMenuStrip property to the ContextMenuStrip.

    Right clicking on the PictureBox will show the ContextMenuStrip.

    Tuesday, November 20, 2012 11:10 PM
  • Wouldn't that make my menustrip non visible though? I want that to be visible at all times. I just want it so that when the user clicks on the picture box , the same items show up as they would like the menustrip such as file, edit, help, and so on. Do you know what I'm saying?
    Tuesday, November 20, 2012 11:11 PM
  • So you want the bar always visible, but when you click on the picturebox, you want the toolstripmenuitems like file, edit.. to become visible? Then you should just use their visible property.

    I'm sorry if i'm not getting it^^ but my english isn't that good =P

    Tuesday, November 20, 2012 11:19 PM
  • Ok, So I am still confused, is there any way you could write the code out for me because that's what I am having trouble doing. Both JohnWein and shortcuts solutions seem like they would work but I am still stuck on how to actually put the answers into code.
    Tuesday, November 20, 2012 11:36 PM
  • There's no code involved in my answer.  Do everything in the designer.
    Tuesday, November 20, 2012 11:38 PM
  • private void pictureBox1_Click(object sender, EventArgs e)
            {
                fileToolStripMenuItem.Visible = true;
                editToolStripMenuItem.Visible = true;
                helpToolStripMenuItem.Visible = true;
            }
    
    private void Form1_Load(object sender, EventArgs e)
            {
                fileToolStripMenuItem.Visible = false;
                editToolStripMenuItem.Visible = false;
                helpToolStripMenuItem.Visible = false;
            }
    Something like this =D

    • Proposed as answer by Jason Dot Wang Thursday, November 22, 2012 7:20 AM
    • Marked as answer by Jason Dot Wang Wednesday, November 28, 2012 9:12 AM
    Tuesday, November 20, 2012 11:52 PM