Link to home
Create AccountLog in
Avatar of directxBOB
directxBOBFlag for Ireland

asked on

C# Virtual Close

I am getting:

"Use the new keyword if hiding was intended"

While it's only a warning I would like to eliminate it as I know it's something simple I am not doing.

My code is:
private void menuItem1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        public virtual void Close()
        {
            string str2 = @"Are you sure you wish to quit? Any changes you have made will be lost.";
            string caption2 = "Confirm Addon Exit";
 
            DialogResult dResult;
            dResult = MessageBox.Show(str2, caption2, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
 
            if (dResult == DialogResult.Yes)
            {
                base.Close();
            }
        }

Open in new window

Avatar of Bruce_1975
Bruce_1975

You have to override the close method of the base class.

Regards,
Bruce
public override void Close()
{
   ....
}

Open in new window

Avatar of directxBOB

ASKER

Yeah I was thinking that but I get:

Error      3      'Form1.Close()': cannot override inherited member 'System.Windows.Forms.Form.Close()' because it is not marked virtual, abstract, or override      
ASKER CERTIFIED SOLUTION
Avatar of Bruce_1975
Bruce_1975

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer