Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# Virtual Close

Posted on 2008-06-16
3
Medium Priority
?
553 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 2000 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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

877 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