views:

25

answers:

2

Hi, I have custom control which i am rendering inside dailouge box. this custom control has a link lable lnkLable. I want to close the opened window when i click on lnkLable.

right now i am finding the parent of my conrol which will be dialouge control in the end and then calling the dispose method of that, which i dont feel very good technique to do this.

Thanks in advance for your help/suggestions.

regards, ashish kalia

A: 

Use the Close() method on the form to close it.

  private void button1_Click(object sender, EventArgs e)
  {
     Control btn = sender as Control;
     Form    frm = btn.Parent as Form;
     frm.Close();
  }

If it's a modal dialog you can also close it by calling the Hide() method because modal dialogs are automatically destroyed the modal pump exits, and the pump will exit when the dialog is hidden.

John Knoeller
A: 

Rather try using Control.FindForm Method

You have to remember that the control might not be directly on the form, but inside another container, like a panel, in which case the parent of your control will not be the form.

Once yuo have the instance of the form, rather use Form.Close Method

astander