?
Solved

C# how to display message box without form

Posted on 2010-08-29
16
Medium Priority
?
2,928 Views
Last Modified: 2013-12-27
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.
0
Comment
Question by:atomicgs12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +2
16 Comments
 
LVL 2

Expert Comment

by:hilltop
ID: 33555581
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 33555592
Easily:

Just call:

System.Forms.MessageBox.ShowDialog("This is your text");
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 33555594
Sorry:

System.Windows.Forms.MessageBox.ShowDialog("This is your text");
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 33555603
Forgot again - you also need to add a reference to your project: to System.Windows.Forms.
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 33555612
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
 

Author Comment

by:atomicgs12
ID: 33555648
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
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 1000 total points
ID: 33555744
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
 
LVL 16

Assisted Solution

by:Vikram Singh Saini
Vikram Singh Saini earned 1000 total points
ID: 33555951
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
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 33556903
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
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 33562637
ramkisan, is your answer somehow different from mine?!
0
 

Author Closing Comment

by:atomicgs12
ID: 33563765
Every one gave great answers but I am awarding the points to first correct answer. Thank You all
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 33564328
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
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33589457
No response from Author yet.
0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33605385
Hi,

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

Regards,
VSS
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question