Link to home
Start Free TrialLog in
Avatar of atomicgs12
atomicgs12Flag for United States of America

asked on

C# how to display message box without form

I have a C# console application written for windows mobile. Is there a way to display a message box/dialog to the user if I don't have a form class in my application? Short example would be nice.
Avatar of hilltop
hilltop
Flag of United States of America image

Easily:

Just call:

System.Forms.MessageBox.ShowDialog("This is your text");
Sorry:

System.Windows.Forms.MessageBox.ShowDialog("This is your text");
Forgot again - you also need to add a reference to your project: to System.Windows.Forms.
One more my mistake: Show, not ShowDialog. I tested the code below :)
        static void Main(string[] args)
        {
                System.Windows.Forms.MessageBox.Show("Hello");
        }

Open in new window

Avatar of atomicgs12

ASKER

jimbel -

When I cut and paste your example into my code I am getting this error:
"Error      1      The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)"

am I missing something in my directives? Is there something in my AssemblyInfo.cs I should be including?
ASKER CERTIFIED SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If we want to pop up messagebox in console app, we should add the reference
to System.Windows.Forms.dll. You could refer to the following code and I
hope it's useful for you,

using System;

namespace ConsoleApplication1
{
      class Class1
      {
                [STAThread]
               static void Main(string[] args)
               {
                     System.Windows.Forms.MessageBox.Show("Hello World");
               }
       }
}
ramkisan, is your answer somehow different from mine?!
Every one gave great answers but I am awarding the points to first correct answer. Thank You all
anarki_jimbel,
Sorry if you think I have reapeted ur answer., But I havn't read your all the comments before answering the question.

Regards,
Ramkisan
No response from Author yet.
Hi,

Comment ID:33555951 should be also accepted as solution to the Author's question.

Regards,
VSS