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.
atomicgs12Asked:
Who is Participating?
 
anarki_jimbelConnect With a Mentor Commented:
Have you added a reference to your project? Go to the solution explorer, click "Add reference" and select Syste. Windows.Forms from the list.
0
 
anarki_jimbelCommented:
Easily:

Just call:

System.Forms.MessageBox.ShowDialog("This is your text");
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
anarki_jimbelCommented:
Sorry:

System.Windows.Forms.MessageBox.ShowDialog("This is your text");
0
 
anarki_jimbelCommented:
Forgot again - you also need to add a reference to your project: to System.Windows.Forms.
0
 
anarki_jimbelCommented:
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

0
 
atomicgs12Author Commented:
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?
0
 
Vikram Singh SainiConnect With a Mentor Software Engineer cum AD DeveloperCommented:
Hi,

Please check code.

Regards,
VSS

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

class Program
{
    [DllImport("User32")]
    public static extern int MessageBox(int Hwnd, string text, string caption, int type);

    static void Main(string[] args)
    {

        MessageBox(0, "You are watching message box!", "Information", 5);
    }
}

Open in new window

0
 
Ramkisan JagtapLead DeveloperCommented:
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");
               }
       }
}
0
 
anarki_jimbelCommented:
ramkisan, is your answer somehow different from mine?!
0
 
atomicgs12Author Commented:
Every one gave great answers but I am awarding the points to first correct answer. Thank You all
0
 
Ramkisan JagtapLead DeveloperCommented:
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
0
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
No response from Author yet.
0
 
Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
Hi,

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

Regards,
VSS
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.