How to close form

后端 未结 8 2131
南旧
南旧 2021-02-18 23:54

Ok, so a Windows Forms class, WindowSettings, and the form has a \"Cancel\"-button. When the user clicks the button, the dialog DialogSettingsCancel will pop-up up and ask the u

8条回答
  •  伪装坚强ぢ
    2021-02-19 00:01

    Your closing your instance of the settings window right after you create it. You need to display the settings window first then wait for a dialog result. If it comes back as canceled then close the window. For Example:

    private void button1_Click(object sender, EventArgs e)
    {
        Settings newSettingsWindow = new Settings();
    
        if (newSettingsWindow.ShowDialog() == DialogResult.Cancel)
        {
            newSettingsWindow.Close();
        }
    }
    

提交回复
热议问题