I am trying to make a button that when clicked pops up a new form with a yes and no button and then make an if statement based on what button is pressed. Here is my current code:

```
        private YesNoMessageBoxResized newBoxResized;
        private string buttonClickResult;

        public void YesNoNewMessageBox(string title, string message,string buttonYes, string buttonNo)
        {
            YesNoMessageBoxResized msgResized = new YesNoMessageBoxResized(title, message, buttonYes, buttonNo);
            msgResized.StartPosition = FormStartPosition.CenterScreen;
            msgResized.TopMost = true;

            Button yesButtonResize = new Button();
            Button noButtonResize = new Button();

            //yes button
            yesButtonResize.Text = buttonYes;
            yesButtonResize.Size = new Size(150, 80);
            yesButtonResize.Font = new Font("Arial", 26);
            yesButtonResize.Location = new Point(100, 150);

            //no button
            noButtonResize.Text = buttonNo;
            noButtonResize.Size = new Size(150, 80);
            noButtonResize.Font = new Font("Arial", 26);
            noButtonResize.Location = new Point(300, 150);

            //make a copy of the current form
            newBoxResized = msgResized;

            //eventhandlers
            yesButtonResize.Click += YesButtonResizeClicked;
            noButtonResize.Click += noButtonResizeClicked;

            newBoxResized.Controls.Add(yesButtonResize);
            newBoxResized.Controls.Add(noButtonResize);
            msgResized.Show();
        }

        private void YesButtonResizeClicked(object o, EventArgs sEA)
        {
            this.buttonClickResult = "true";
            this.newBoxResized.Close();
        }

        private void noButtonResizeClicked(object o, EventArgs sEA)
        {
            this.buttonClickResult = "false";
            this.newBoxResized.Close();
        }

        private void buttonRestoreDefaults_Click(object sender, EventArgs e)
        {

            YesNoNewMessageBox("Restore Defaults?", "Restore Defaults?", "Yes", "No");

            if (this.buttonClickResult == "true")
                this.restoreDefaults();

        }

```

My problem is that after hitting yes and closing the form that pops up, buttonClickResult is not seen as true and therefore the restore default function I am calling is not called. Only when clicking on the "RestoreDefaults" button again is the function called. So, it seems that the onclick event for buttonRestoreDefaults\_Click isn't reconizing the onclick for the yes or no buttons in the form that popups until clicking on it again. Is there a way around this or some sort of implementation to fix this? Thank you.

Also, here is the code for the class. I was thinking about using delegates and event handlers, but I am not sure if I actually need that since what I have works, but just doesn't update the variable on closing correctly:

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

    public class YesNoMessageBoxResized : Form
    {
        private Label labelMessage;

        //no default button specified
        public YesNoMessageBoxResized(string title, string message, string buttonYes, string buttonNo)
        {
            InitializeComponent();
            this.Text = title;
            this.labelMessage.Text = message;
            this.Deactivate += MyDeactivateHandler;
        }

        public YesNoMessageBoxResized()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.labelMessage = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // labelMessage
            // 
            this.labelMessage.AutoSize = true;
            this.labelMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.labelMessage.Location = new System.Drawing.Point(12, 31);
            this.labelMessage.Name = "labelMessage";
            this.labelMessage.Size = new System.Drawing.Size(165, 29);
            this.labelMessage.TabIndex = 3;
            this.labelMessage.Text = "labelMessage";
            // 
            // YesNoMessageBoxResized
            // 
            this.ClientSize = new System.Drawing.Size(572, 268);
            this.Controls.Add(this.labelMessage);
            this.Name = "YesNoMessageBoxResized";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        protected void MyDeactivateHandler(object sender, EventArgs e)
        {
            this.Close();
        }

        public delegate void buttonYes_ClickResultEvent(object o, EventArgs sEA);
        public event buttonYes_ClickResultEvent choiceResult;

    }
 public class buttonYes_ClickResultEvent : EventArgs
 {
     public buttonYes_ClickResultEvent(bool choice)
     {
         this.buttonResult = choice;
     }

     public bool buttonResult;
 }

```

\*\*I posted this on codereview, but then they told me to post it here since it deals with solving a problem.