I need help. I have winform, like one which is shown on picture, so I want to improve next things, when I click on first button, on the right side will be showed content from another winform, is this possible? I don't want to use panels.
-
You talking about `MDI FORM` – Rahul May 25 '17 at 09:37
-
3https://stackoverflow.com/questions/7691468/can-i-host-a-windows-form-inside-a-control/7692113#7692113 – Hans Passant May 25 '17 at 09:44
-
1_I don't want to use panels_ Why? What do you want to use? – Pikoh May 25 '17 at 09:45
-
Because, it will be messy. For example, I have 10 buttons on left side, and every button has another content, so for every button I have to create one panel, and edit them. – Amer Čehić May 25 '17 at 09:48
9 Answers
Why don't you just embed a single UserControl
dynamically to represent the current page or if you want to do everything at design-time - a custom TabControl
?
showed content from another winform
You generally don't embed a popup window into another, rather controls. Otherwise you have to deal with hiding Minimise, Maximise, Close etc.
-
i'm trying to implement tab control, but I can't hide navigation bar – Amer Čehić May 25 '17 at 10:24
-
1Use a UserControl as recommanded. It works quite well and it is not hard to manage the pages yourself. Usually, I would only kept the current page available. Alternatively, you can use third-party component that has tab controls that allows to hide the tab bar. – Phil1970 May 25 '17 at 11:08
MDI Form is the best solution for you.
Use: this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;` to make your child Forms more beautiful in your project!
If you want the MDI parent to auto-size the child form you can code like this.
Code Example:
private void Form1_Load(object sender, EventArgs e)
{
IsMdiContainer = true;
}
private void btnHotel_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show();
frm2.MdiParent = this;
}
private void btnCaffe_Click(object sender, EventArgs e)
{
Form3 frm3 = new Form3();
frm3.Show();
frm3.MdiParent = this;
}

- 11
- 3
You can use TabControl control -> for each specific content you want to display you just have to add a TabPage to TabControl and when a specific menu option is selected, just switch to required TabControl page.
myTabControl.SelectedIndex = 1; // for selecting and displaying page with index 1
To hide navigation header of myTabControl, set those props (in constructor or in Form_Load event:
myTabControl.ItemSize = new Size(0, 1);
myTabControl.SizeMode = TabSizeMode.Fixed;
Then, you have only content of the TabControl page displayed, without navigation header.

- 935
- 8
- 27
-
-
Try to add one more line: `myTabControl.Appearance = TabAppearance.FlatButtons;` I am 100% that this works :) – pitersmx May 25 '17 at 10:14
-
-
try in different order: `myTabControl.Appearance = TabAppearance.FlatButtons;` `myTabControl.SizeMode = TabSizeMode.Fixed;` `myTabControl.ItemSize = new Size(0, 1);` – pitersmx May 25 '17 at 10:40
First make it's this.IsMdiContainer = true;
either from design time or run time.
then at the button's click event place the following code.
childForm frm = new childForm();
frm.MdiParent = this; //the current mdi parent form
frm.FormBorderStyle = FormBorderStyle.None;
frm.Dock = DockStyle.Fill;
frm.Show();

- 6,725
- 3
- 25
- 47

- 241
- 3
- 18
You can use mdi (multiple-document interface): when you want a form start inside mainform, use this following code:
Dim hotelForm As New HotelForm()
HotelForm.MdiParent = Me // Me is your parent form want to open hotelForm inside
HotelForm.Show()

- 1
All forms have a property TopLevel
, by setting this property to false, then you can deal with that form as a control, and add it to a panel control.
See below psuedo code:
Form2 newForm = new Form2();
newForm.TopLevel = false;
myPanel.Controls.Add(newForm);
newForm.Show();
After that, your main form design should look like as a navigation control and a panel beside it docked "Fill", then on clicking any navigation button, just create the desired form and set TopLevel
to false, then show it on the panel

- 9,791
- 2
- 19
- 34

- 31
- 3
You have to put a Container control like a panel "pnlHost" in your form and use this for showing any form you want in it
private Form _currentForme;
private void ShowForm(Form frm)
{
_currentForme?.Close();
_currentForme = null;
_currentForme = frm;
_currentForme.TopLevel = false;
_currentForme.TopMost = false;
pnlHost.Controls.Clear();
_currentForme.FormBorderStyle = FormBorderStyle.None;
pnlHost.Controls.Add(_currentForme);
_currentForme.Dock = DockStyle.Fill;
_currentForme.Show();
}

- 109
- 4
I would use MDI parent and child for this.
But I guess you could also finish the child application, build the exe and initiate it as a new process from your Parent application. Check the solution given here. I tried a similar approach long ago and it worked perfectly.

- 79
- 7
Set current form as a MdiParent then use Datagridview to display data from other forms

- 149
- 1
- 2
- 10