Solved

C# Virtual Close

Posted on 2008-06-16
3
548 Views
Last Modified: 2008-06-16
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

0
Comment
Question by:directxBOB
  • 2
3 Comments
 
LVL 6

Expert Comment

by:Bruce_1975
ID: 21792338
You have to override the close method of the base class.

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

Open in new window

0
 

Author Comment

by:directxBOB
ID: 21792539
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      
0
 
LVL 6

Accepted Solution

by:
Bruce_1975 earned 500 total points
ID: 21792580
Hi Ryan,
I mixed it up with overriding the event handlers OnClosing...
To prevent the error message of your function, use following.

Regards,
Bruce

public new void Close()
{
   ....
}

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question