Embedding a winform within a winform (c#)

前端 未结 5 532
我在风中等你
我在风中等你 2020-12-29 08:57

Is it possible to embed a windows form within another windows form?

I have created a windows form in Visual Studio along with all its associated behaviour.

I

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 09:42

    let's say you have 2 projects win1 and win2. both are winform projects. you look for embeding win2 in win1.

    solution:

    open the win2 project and change the output type to "Class Library" (in Application tab)

    open the project win1, and add the win2 dll project as a ref in win1 project go in the win1 code, and put this :

            win2.Form1 formI = new win2.Form1();
            formI.TopLevel = false;
            formI.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            formI.Size = this.Size;
            formI.BringToFront();
            formI.Visible = true;
            this.Controls.Add(formI);
    

提交回复
热议问题