This is a migrated thread and some comments may be shown as answers.

Form close issue

3 Answers 307 Views
Form
This is a migrated thread and some comments may be shown as answers.
Selvamani
Top achievements
Rank 1
Selvamani asked on 11 Nov 2011, 07:28 AM
Hi,

    i have a form with one button called next .when we click next it will invoke another instance of the same form ,so i want to close the old form before open the new instance of the form.  i am unable to acheieve this. any suggestions on this issue will be helpful for me to solve this issue.

following is the code snippet which i used for the testing purpose of the above said scenario.

   
private void ra_Load(object sender, EventArgs e)
        {
            List<string> firstname = new List<string>();
 
            firstname.Add("SAM");
            firstname.Add("TAYLOR");          
            firstname.Add("ROSE");
 
            GridViewDataRowInfo row;
            for (int i = 0; i < firstname.Count; i++)
            {
                    row = radGridView1.Rows.AddNew();
                    row.Cells[0].Value = firstname[i];               
            }          
        }
 
        private void btnNext_Click(object sender, EventArgs e)
        {
            //this.Close();
            ra newra = new ra();
            newra.ShowDialog();           
        }

Regards,
Selva

3 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 15 Nov 2011, 02:20 PM
Hello Selvamani,

Thank you for writing.

If this is your main form, you cannot close it, because this will terminate your application. The main form can only be hidden by calling this.Hide(). You should be aware that if your main form is hidden and you close all other windows from your app, this will not exit your application. You can call Application.Exit() to close the application at any point or you should make your main form visible at some point so you can close it and exit the application. This case is only valid for non-main forms. If you open a form from the main form and in it you call this code, everything should work fine.

I hope this will help. Should you have further questions, I would be glad to answer them.

Greetings,
Ivan Petrov
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Selvamani
Top achievements
Rank 1
answered on 16 Nov 2011, 06:26 AM
Hi,
        thanks for the valuable suggestion .    
        
        the sample i created and posted is for just to check how to achieve the form closing.
        
        those forms are not main forms.

        in my application i have those kind forms where it will invoke its instance again ,as you said i have used .hide() method to acheive it,
but when i hide it main application is dissappering and visual studio screen is displaying i have to go to taskbar and select the main application to display it again this thing is happening in debugging mode. suppose if i open the application as exe some other application which is running already is getting invoked.

i have attached image for your reference.

thanks & regards
Selva


0
Ivan Petrov
Telerik team
answered on 18 Nov 2011, 10:13 AM
Hello Selvamani,

Thank you for your reply.

It seems you will be creating some sort of a wizard. If this is the case, may I bring to your attention our RadWizard control which was especially developed for this kind of scenarios.
On your question, the Hide method should be used only if you are hiding the main form, because it cannot be closed. For other forms it is all right to use Close. And generally the practice is to first show the new form and then hide/close the old one.

If there is anything else I can help you with, feel free to write back.

Best wishes,
Ivan Petrov
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Tags
Form
Asked by
Selvamani
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Selvamani
Top achievements
Rank 1
Share this question
or