将表单停靠在MDI上

时间:2022-10-20 10:27:48

I am trying to dock a form onto a MDI, but when I use the following code, it just flashes itself and the form disappeared.

我试图将一个表单停靠在MDI上,但是当我使用下面的代码时,它只会自动闪烁并且表单消失了。

        using (frmDock formDock = new frmDock())
        {
            formDock.MdiParent = this;
            formDock.Dock = DockStyle.Left;
            formDock.Show();

        }

1 个解决方案

#1


That's because as soon as that using block ends it disposes the new form you just created. If you did it without the using, the form would stay there. You don't need a using statement as long as you just close it with formDock.Close(). Using statements normally accompany connections to databases or streams to ensure that they get closed/disposed properly and don't cause problems later in your program.

那是因为只要使用块结束它就会处理刚刚创建的新表单。如果你在没有使用的情况下这样做,表格就会留在那里。只要您使用formDock.Close()关闭它,就不需要using语句。使用语句通常伴随着与数据库或流的连接,以确保它们正确关闭/处理,并且不会在程序中导致问题。

Here's one of I'm sure many articles about the using statement out there on the web.

这是我确定很多关于网上使用声明的文章之一。

#1


That's because as soon as that using block ends it disposes the new form you just created. If you did it without the using, the form would stay there. You don't need a using statement as long as you just close it with formDock.Close(). Using statements normally accompany connections to databases or streams to ensure that they get closed/disposed properly and don't cause problems later in your program.

那是因为只要使用块结束它就会处理刚刚创建的新表单。如果你在没有使用的情况下这样做,表格就会留在那里。只要您使用formDock.Close()关闭它,就不需要using语句。使用语句通常伴随着与数据库或流的连接,以确保它们正确关闭/处理,并且不会在程序中导致问题。

Here's one of I'm sure many articles about the using statement out there on the web.

这是我确定很多关于网上使用声明的文章之一。