Solved

C# Virtual Close

Posted on 2008-06-16
3
544 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now