1

I have a mainform with a toolstrip. Buttons on the toolstrip open new sub-forms. These forms are smaller in Y direction than the mainform. They are drawn precisely over the Mainform and you can only see the toolstrip.

see screenshot Full-size image

Now I want to press another button of the toolstrip to close the current active subform and opens a new sub form. But when I press on such a button, the mainwindow gets drawn over the subform (which is understandable) but the button event doesn not get triggered. Than I need to press the button again to open a new sub form and this is inconvenient.

Used code looks as follows

private void MenuButton_Click(object sender, EventArgs e)
    {
        menu_.SetDesktopBounds(0, 0, 1024, 668);
        menu_.Show();

        try { ssp.Close(); } catch { }
        help.Hide();
    }

How can I let the toolstrip buttons remain active after I open a subform?

Dmitry
  • 13,797
  • 6
  • 32
  • 48
bask185
  • 377
  • 1
  • 3
  • 12
  • Having two forms active at the same time is a no-go, Windows just doesn't support it. – Bob G Sep 08 '17 at 12:07
  • Your problem is not active forms or the number of them, it's simply a focus issue. Look to [this question](https://stackoverflow.com/questions/6947163/activate-a-form-and-process-button-click-at-the-same-time) for guidance. – DonBoitnott Sep 08 '17 at 13:32
  • Instead of showing child forms over the parent, just add them to a panel in the parent form. – Reza Aghaei Sep 08 '17 at 22:06
  • @RezaAghaei And how do I do that? Can I really add entire forms to a panel in the UI? DonBoitnott thank you, but I cannot get it to work. I added the class and I tried the function but it doesn't seem to have any effect. I don't know what else I have to change in code to get that to work – bask185 Sep 11 '17 at 06:50
  • @bask185, yes, you can, just set its `Toplevel=false`, then add it to the `panel.Controls` collection, then call it's `Show` method. – Reza Aghaei Sep 11 '17 at 07:08
  • @RezaAghaei I have one working so this is nice. But the other won't work. Are the known problems with doing this with more than 1 panel or would I have screwed something up in code. And can you attach more than 1 form to a panel? – bask185 Sep 11 '17 at 08:29
  • It's as easy as I described without any other considerations. Just make sure that the panel that you add the form to it, is visible. – Reza Aghaei Sep 11 '17 at 09:17
  • Also you may find these post useful: [How to create vertical navigation bar in Windows Forms?](https://stackoverflow.com/q/36243690/3110834). Also if you want to have multiple panel, take a look at this [wizard-like control](https://stackoverflow.com/a/40633229/3110834) in the second part of the linked answer. – Reza Aghaei Sep 11 '17 at 09:19

1 Answers1

0

Separate toolstrip to another form which will control which form will be visible above him.

koca2000
  • 67
  • 12