A
A
attlear2018-12-23 02:34:38
C++ / C#
attlear, 2018-12-23 02:34:38

How to make a window within a window in C#?

Good day. Faced a problem. Working with Windows Forms in VS 2017 in C#. I want to make a window that, when a button is pressed, will open another window (form2, as I assumed). Tried. In order for the second form to open within the boundaries of the first and as a child, I subtracted about the MdiParent and IsMdiParent functions. In the parameters of the first form, set the value to true for IsMdiParent (the parent form). It looks like it works, but when you specify the parent parameter, the background becomes gray and does not change with other parameters (the same ColorBack displays the selected color while VS initializes the code, then it returns to gray) https://imgur.com/a/LLCtSMa
Initially, it was just needed area, or dynamic, which would be located inside the form with its own set of elements: textboxes, buttons, etc.

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            IsMdiParent = true; // Здесь выдает исключение, поэтому организовал через свойства формы.

            this.WindowState = FormWindowState.Maximized;
            this.FormBorderStyle = FormBorderStyle.None;

            Form2 s = new Form2();
            s.MdiParent = this;
            s.Show();
        }
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir S, 2018-12-23
@hePPer

it is easier to do this by adding a custom control - place the necessary elements on it and add/remove it to the main form at the right time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question