By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,465 Members | 1,435 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,465 IT Pros & Developers. It's quick & easy.

Want to use MessageBox without showing the Form

P: n/a
Hello!

I have a small program that just copy a file and make some checks in main
then I just want to inform
the user about something by using a MessageBox.

I tried to use this in the MessageBox that is located in the main function.
This cause compile error because you are not allowed to use this in a static
function.

Now what I want to do is to inform a user by using a MessageBox without
showing the form is that possible?
To show a empty form that the user have to close doesn't seem quite right.

//Tony

Feb 6 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"TonyJ" <jo*****************@telia.comwrote:
I have a small program that just copy a file and make some checks in main
then I just want to inform
the user about something by using a MessageBox.

I tried to use this in the MessageBox that is located in the main
function.
Why?

What MessageBox do you have in the Main function?
This cause compile error because you are not allowed to use this in a
static
function.

Now what I want to do is to inform a user by using a MessageBox without
showing the form is that possible?
To show a empty form that the user have to close doesn't seem quite right.
As you haven't shown your own attempt to try it, I don't have a clue what
the problem is, but here's a working example, straightforward:
---------------------------------------------------

using System.Windows.Forms;

namespace ConsoleAppWithMessageBox
{
class Program
{
static void Main(string[] args)
{
MessageBox.Show("This works very well");
}
}
}

---------------------------------------------------

/// Bjorn A
Feb 6 '07 #2

P: n/a
Hi Tony,
I'm not sure why you have a problem showing a message box in Main...?

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
MessageBox.Show("hello world");
}
}
}

John

On Feb 6, 6:15 am, "TonyJ" <johansson.anders...@telia.comwrote:
Hello!

I have a small program that just copy a file and make some checks in main
then I just want to inform
the user about something by using a MessageBox.

I tried to use this in the MessageBox that is located in the main function.
This cause compile error because you are not allowed to use this in a static
function.

Now what I want to do is to inform a user by using a MessageBox without
showing the form is that possible?
To show a empty form that the user have to close doesn't seem quite right.

//Tony

Feb 6 '07 #3

P: n/a
Hi,

"TonyJ" <jo*****************@telia.comwrote in message
news:uq**************@TK2MSFTNGP05.phx.gbl...
| Hello!
|
| I have a small program that just copy a file and make some checks in main
| then I just want to inform
| the user about something by using a MessageBox.
|
| I tried to use this in the MessageBox that is located in the main
function.

There is no function inside a function, this is not allowed in C#

Also you can safely use MessageBox.Show directly from the main method
without any problem.
--
Ignacio Machin
machin AT laceupsolutions com
Feb 6 '07 #4

P: n/a
TonyJ,
There shouldn't be a problem to use MessageBox from the Main method. Mabe
the problem is that somewhere in the code you are trying to use some
instance member e.g. a property or field that keeps the text for the
message. Main method is a static one so it has access only to static
members.

Post some sample code that demostrates the problem. I believe your problem
is pretty simple one.
--
Stoitcho Goutsev (100)

"TonyJ" <jo*****************@telia.comwrote in message
news:uq**************@TK2MSFTNGP05.phx.gbl...
Hello!

I have a small program that just copy a file and make some checks in main
then I just want to inform
the user about something by using a MessageBox.

I tried to use this in the MessageBox that is located in the main
function.
This cause compile error because you are not allowed to use this in a
static
function.

Now what I want to do is to inform a user by using a MessageBox without
showing the form is that possible?
To show a empty form that the user have to close doesn't seem quite right.

//Tony

Feb 6 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.