Form close issue

4 posts, 0 answers
  1. Selvamani
    Selvamani avatar
    7 posts
    Member since:
    Nov 2011

    Posted 11 Nov 2011 Link to this post

    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
  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 15 Nov 2011 Link to this post

    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.

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Selvamani
    Selvamani avatar
    7 posts
    Member since:
    Nov 2011

    Posted 16 Nov 2011 Link to this post

    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


  5. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 18 Nov 2011 Link to this post

    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.

Back to Top