Want to use MessageBox without showing the Form

T

TonyJ

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
 
B

Bjorn Abelli

TonyJ said:
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");
}
}
}
 
J

John Duval

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
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

| 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.
 
S

Stoitcho Goutsev \(100\)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top