Search code examples
c#winformsmessagebox

Recycle Bin image displayed on message box


Writing a winforms application. I have created a yes/no message box, displayed to the user when they are trying to delete a file but I would like to add the recycle bin image to the message. How do you get access, for use with things like message boxes systems icons/images?

MessageBox.Show("Please confirm that you would like to delete the folder named:" + fldnme, 
                        "Confirm Folder Delete", 
                        MessageBoxButtons.YesNo, 
                        MessageBoxIcon.Exclamation);

Obviously I would be replacing the messageboxicon with?

Thanks


Solution

  • Short answer: you cannot.

    The Win32 MessageBox window only lets you choose one of four icons (the other members of MessageBoxIcon are synonyms) that corresponds to the purpose of a messagebox:

    • Ask the user a confirmation question (a Yes/No messagebox with a Question-mark icon)
    • To warn the user (usually a single button with a warning triangle icon)
    • To inform the user of some information (usually a single button with an "i" icon)
    • To inform the user of a serious error (usually a single button with a red stop icon)

    In your use-case, to ask the user to confirm the deletion of a file, you should use either the Question-mark icon or the Warning triangle icon.

    I'm going to assume that you call File.Delete if the user selects Yes rather than moving the file to the Recycle Bin. If this is the case then you really shouldn't use the Recycle Bin icon (even if you could) because you aren't moving it to the bin, you're deleting it straight away.