CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2010
    Posts
    5

    MessageBox in C#

    Hi
    I am a C++ programmer but am having to do a small app in C#
    I want to display a Message Box so wrote
    Code:
    MessageBox.Show("The diagram already exists - Do you want to overrite?", "Diagram Exists",
             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    But the compiler says
    C:\VSProjects\Addin2\Class1.cs(180,29): error CS0103: The name 'MessageBox' does not exist in the current context

    How can I fix this?

    Graham

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: MessageBox in C#

    Make sure System.Windows.Forms is referenced.

  3. #3
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: MessageBox in C#

    Btw SomersetBoy, in Visual Studio you can right click on Types that you know should be right, but aren't scopped, and go to Resolve->Include namespace. It will automatically add the namespace using for you, or explicitly scope the Type in question.

  4. #4
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: MessageBox in C#

    Quote Originally Posted by mariocatch View Post
    Btw SomersetBoy, in Visual Studio you can right click on Types that you know should be right, but aren't scopped, and go to Resolve->Include namespace. It will automatically add the namespace using for you, or explicitly scope the Type in question.
    That's indeed a nice feature in VS, but will only work if the type is referenced.

  5. #5
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: MessageBox in C#

    Stress that assembly System.Windows.Forms.dll is meant, because the namespace name is the same, but you haven't access to the namespace until you reference the assembly.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: MessageBox in C#

    Quote Originally Posted by dannystommen View Post
    That's indeed a nice feature in VS, but will only work if the type is referenced.
    Yep, but that's where Msdn comes into play:

    MessageBox Class

    Displays a message box that can contain text, buttons, and symbols that inform and instruct the user.



    Namespace: System.Windows.Forms
    Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured