-5

When I type - MessageBox.Show("Deleted!");

The C# editor red marks the 'MessageBox.Show' and shows

'The name MessageBox.Show doesn't exist in the current context. '

I have used 'using System.Windows.Forms;' Here also it red marks the 'Forms'.

Please Help Me. Thanks.

SKJ
  • 5
  • 2

3 Answers3

0

You need to include namespace top of the script.

Winform >

using System.Windows.Forms;

WpfForm >

using System.Windows;

Edited :

Since you added it's console app, you need to do additional things.

Right click 'Reference' on your project and click add

Search System.Windows.Forms and add it.

after that, you can include System.Windows.Forms and use it.

Arphile
  • 841
  • 6
  • 18
0

As you've deduced, MessageBox does indeed belong to System.Windows.Forms. Unless you have created a Windows Forms project, the reference to this library will not automatically be added to your project.

You can add it to other project types by doing this:

  1. Right-click "References" under your project in the Solution Explorer
  2. Click "Add reference"
  3. Select "Assemblies"
  4. Check "System.Windows.Forms"
  5. Finally, click OK.

After doing this, your using System.Windows.Forms should no longer show the red underline, and your message box code should work. Note that normally console output would be output to the console and not to a messagebox, hence why it isn't available by default.

I don't believe message box functionality is available in .NET Core or .NET Standard (see here), so if you made a .NET Core Console Application (as opposed to .NET Framework), you might want to output information in a different way.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
0

You have to add a Reference on "System.Windows.Forms" in your project references.

Right click on "References" folder, select Add. Then Chose "Assemblies", then search for System.Windows.Forms and add the reference to your project.

user11909
  • 1,235
  • 11
  • 27