2

It is clear with modal forms...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim f As New myForm
    f.ShowDialog(Me)
    f.Dispose
End Sub

But what to do with non modal forms?
Where to dispose it?

    Dim f As New myForm
    f.Show(Me)
    f.Dispose

This will close newly created form immediately so f.Dispose shouldn't stay here.
If I put that in _FormClosing handler will be nice but not enough since we can have few instances of that form running.

1) So, where and how to dispose non modal forms opened like in second example?
2) Is here any event to know that our child form closes?

4

1 に答える 1

3

Dispose次の 2 つの条件を除いて、フォームのリソースは自動的にクリーンアップされるため、モードレス フォームを呼び出す必要はありません。

  1. マルチ ドキュメント インターフェイス (MDI) アプリケーションの一部であり、フォームが表示されない
  2. を使用してフォームを表示しましたShowDialog

.Dispose()あなたのシナリオは上記の 2 つの条件のいずれにも当てはまらないため、手動呼び出しは必要ないため、どこに配置するかについて心配する必要はありません。

詳細については、 Form.Close メソッドのドキュメントを参照してください。

于 2013-10-16T16:04:57.693 に答える