0

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.

enter image description here

stuartd
  • 70,509
  • 14
  • 132
  • 163

9 Answers9

2

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
  • 1
    Use 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
1

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;
    }
trex
  • 11
  • 3
0

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.

pitersmx
  • 935
  • 8
  • 27
0

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();

output

Farhad Bagherlo
  • 6,725
  • 3
  • 25
  • 47
0

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()
0

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

G42
  • 9,791
  • 2
  • 19
  • 34
0

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();
    }
Boutamen
  • 109
  • 4
0

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.

-1

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

jackhelsi
  • 149
  • 1
  • 2
  • 10