How to close form

后端 未结 8 2138
南旧
南旧 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:05

    send the WindowSettings as the parameter of the constructor of the DialogSettingsCancel and then on the button1_Click when yes is pressed call the close method of both of them.

    public class DialogSettingsCancel
    {
        WindowSettings parent;
    
        public DialogSettingsCancel(WindowSettings settings)
        {
            this.parent = settings;        
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            //Code to trigger when the "Yes"-button is pressed.
            this.parent.Close();
            this.Close();
        }
    }
    

提交回复
热议问题