views:

922

answers:

1

Hi there,

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.

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

        }
+2  A: 

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.

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

ryanulit