By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,975 Members | 1,035 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,975 IT Pros & Developers. It's quick & easy.

Dipose() Doubts

P: n/a
Hi...

I have a main MDI form where I load (in a menu click method) my MDI child
forms, like in example below:

private void tStpPrincipalUsers_Click(object sender, EventArgs e)
{
FormUsers frmUsers = new FormUsers();
frmUsers.MdiParent = this;
frmUsers.WindowState = FormWindowState.Maximized;
frmUsers.Show();
}

In the frmUsers I have this method in a tool bar button:

private void tStpBtnExit_Click(object sender, EventArgs e)
{
this.Close();
this.Dispose();
}

Is right call the dispose method here? If is not right where do I shall the
dispose method?

Other doubt is: I have a form loaded like a Dlg (called by the ShowDialog
method):

private void tStpBtnEdit_Click(object sender, EventArgs e)
{
DlgUsers userDlg = new DlgUsers();
userDlg.userID =
Convert.ToInt32(dataGridView1.CurrentRow.Cells["ID"].Value);
userDlg.LoadUser();
userDlg.ShowDialog();
userDlg.Dispose();
}

Is right call the dispose method here?
Mar 31 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
With regard to your ShowDialog, wrap it all in a using statement and
the form will be automatically disposed for you

using(DlgUsers userDlg = new DlgUsers())
{
userDlg.userID =
Convert.ToInt32(dataGridView1.CurrentRow.Cells["ID"].Value);
userDlg.LoadUser();
userDlg.ShowDialog();
}

Mar 31 '06 #2

P: n/a
As Jason, wrap the ShowDialog form in a using and it will be disposed.
For a form shown using .Show, it is automatically disposed when it is
closed.

Mar 31 '06 #3

P: n/a
Chris, if the form is a MDI child form is it automatically disposed when it
is closed too?

"Chris Dunaway" <du******@gmail.com> escreveu na mensagem
news:11**********************@i39g2000cwa.googlegr oups.com...
As Jason, wrap the ShowDialog form in a using and it will be disposed.
For a form shown using .Show, it is automatically disposed when it is
closed.

Apr 3 '06 #4

P: n/a
I cannot find any information that an MDI form behaves differently than
any other form. AFAIK, when a form is closed that was shown with just
the Show method, it is disposed.

Apr 3 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.