How do I create a form able to contain other forms that are navigated using buttons and kept running in the background?

StackOverflow https://stackoverflow.com/questions/21344748

Frage

I'm trying to create a form that is able to navigate between other forms that will be running in the background upon initializing the 'parent' form; one side of the form will contain the buttons, each button leading to a different subform (or child form), unlike using next/previous navigation method. I also want to make it that each 'window' or 'tab' in the main form will be populated with a sub form whose code is written separately from the parent form. Meaning, instead of constructing sub forms inside the parent form's code, I'd much prefer to reference/call them to the parent form, each in it's respective tab.

Operationally speaking, there's a main form, and buttons on one side, and an empty space on the other, that presents sub forms depending on what button you clicked. and those sub forms run in the background already populated as the form initializes. For example, I click "Item Management" the empty space will show me an already populated 'ItemFrm'. I make a few changes in my item database, confirm them, and proceed to look at my transfers. If I click "Transfers" the 'ItemFrm' will switch to, let's say, 'TransFrm'. If I want to go back to 'ItemFrm' after I'm done with "Transfers", it will go back to 'ItemFrm' exactly as I left it.

I tried lurking here for a while now, tried using things like TabControl and MDI but I seem to lack the expertise to solve this particular problem. I've tried making a sub form appear exclusively in the TabControl TabPage, but what happened is that it spawned at the edge of the MDI parent form. I seem to be lost.

Any and all help will be appreciated!

War es hilfreich?

Lösung

Based on your description, I would use a standard (SDI) form with a SpliContainer that has buttons in the left panel, and a TabControl in the right panel.

The Buttons trigger TabPage changes, all controls are ready to go and state saved between swaps. An MDI solution will not work, because an MDI form shouldn't contain controls (you could force it, but bad idea), like the left side buttons you want.

It is possible to hide the tabs, so that it doesn't look like a TabControl.

I suggest you take another stab at it. Whatever problems you have, post them and get help.

EDIT:

OP's comment, with better formatting:

Also, to bind a Form to my TabPage, I had to use this small piece of code

ItemFrm itemfrm = new ItemFrm();
itemfrm.TopLevel = false;
itemfrm.Visible = true;
itemfrm.FormBorderStyle = FormBorderStyle.None;
tabControl1.TabPages[0].Controls.Add(itemfrm);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top