locked
How do you stop a MenuStrip control from scrolling? RRS feed

  • Question

  • Am working on a project with a form and a menu strip at the top. I would like the rest of the form to be able to scroll while leaving the menu strip at the top. But when you scroll the form, the menu strip disappears past the top, and you have to scroll back to access the menu.

    Have searched for answers, and the standard one that turns up (including on this forum) is to drag a panel control into the form, then drag the menustrip onto the panel, then set the Dock property of the panel to "Fill" and the Autoscroll property to "True". This answer dates back to 2007, however....

    Tried that on the project, to no avail. Fiddled with everything else I could think of--no dice.

    So I set up a new test project with the sole purpose of making a scrollable form with a menu at the top that doesn't scroll. All it had was a couple of text boxes that were extra tall to make the form scroll. Followed the above directions to a t. Still can't get it to work.

    Did it in both 2012 and 2015 versions of VB Visual Studio. Tried using a split panel; didn't work either. Am using a laptop--no mouse. Form autoscroll set to "True".

    What gives?

    Friday, November 13, 2015 10:18 PM

Answers

  • the standard one that turns up (including on this forum) is to drag a panel control into the form, then drag the menustrip onto the panel, then set the Dock property of the panel to "Fill" and the Autoscroll property to "True".

    Have you tried adding the MenuStrip to an empty form then adding the panel and set the panel's Dock to Fill.

    If you add the MenuStrip to the panel then it will scroll with all the other controls.  If it's added to the form, it won't.

    • Proposed as answer by IronRazerz Saturday, November 14, 2015 1:37 AM
    • Marked as answer by Warren Platts Saturday, November 14, 2015 5:11 PM
    Saturday, November 14, 2015 12:23 AM

All replies

  • Warren,

    Is the menu strip control not docked to the top?


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Saturday, November 14, 2015 12:05 AM
  • the standard one that turns up (including on this forum) is to drag a panel control into the form, then drag the menustrip onto the panel, then set the Dock property of the panel to "Fill" and the Autoscroll property to "True".

    Have you tried adding the MenuStrip to an empty form then adding the panel and set the panel's Dock to Fill.

    If you add the MenuStrip to the panel then it will scroll with all the other controls.  If it's added to the form, it won't.

    • Proposed as answer by IronRazerz Saturday, November 14, 2015 1:37 AM
    • Marked as answer by Warren Platts Saturday, November 14, 2015 5:11 PM
    Saturday, November 14, 2015 12:23 AM

  • Have you tried adding the MenuStrip to an empty form then adding the panel and set the panel's Dock to Fill.

    If you add the MenuStrip to the panel then it will scroll with all the other controls.  If it's added to the form, it won't.

    I may have misunderstood - I assumed that the menustrip control was added to the form already, but it does need to be - docked to the top though, not to fill.

    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    Saturday, November 14, 2015 12:28 AM
  • Have you tried adding the MenuStrip to an empty form then adding the panel and set the panel's Dock to Fill.

    If you add the MenuStrip to the panel then it will scroll with all the other controls.  If it's added to the form, it won't.

    Thanks for all the quick replies guys!

    OK, the technique is as follows:

    1. dock the menustrip to the top of the form--it doesn't have to be empty;

    2. add a panel to the form;

    3. then add all other controls to the panel

    4. set panel Dock = Fill and Autoscroll to True 

    The panel will then scroll, but the menu strip will stay at the top.

    That works perfectly and is very simple to apply. (Wish I had thought of that!)

    I was doing the exact opposite: adding the menustrip to the top of the panel, while leaving the other controls on the main form.

    Thanks again all! :)


    • Edited by Warren Platts Saturday, November 14, 2015 5:44 PM clarify
    Saturday, November 14, 2015 5:10 PM
  • Caveat:

    I did a global cut 'n' paste on the original project to move the controls from the main form to the new panel, and got the menu to stop scrolling. However, this caused all the buttons, checkboxes, menu items, textbox changes to stop working.

    So I had to go through each sub for that event, and at the end of the top line of the sub I had to add a "Handles ControlName.Click" (for buttons, checkboxes, and menu items) and "Handles TextBoxName.TextChanged" for the textboxes.

    Now everything is back to working smoothly, and the menu stays where it's supposed to. :-)

    Saturday, November 14, 2015 7:07 PM
  • Caveat:

    I did a global cut 'n' paste on the original project to move the controls from the main form to the new panel, and got the menu to stop scrolling. However, this caused all the buttons, checkboxes, menu items, textbox changes to stop working.

    So I had to go through each sub for that event, and at the end of the top line of the sub I had to add a "Handles ControlName.Click" (for buttons, checkboxes, and menu items) and "Handles TextBoxName.TextChanged" for the textboxes.

    Yes that can be a pain.

    If you ever have to do it again then try this.

    1.  Save All.

    2. Cut all the controls.

    3. Paste them to the panel

    4. Immediately go to the code and press Ctrl-Z which should restore all the handles.

    If you finish with a mess then close without saving.

    Saturday, November 14, 2015 7:27 PM