Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# Virtual Close

Posted on 2008-06-16
3
Medium Priority
?
552 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 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