Solved

C# Virtual Close

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

920 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

12 Experts available now in Live!

Get 1:1 Help Now