Click to See Complete Forum and Search --> : Use MessageBox without using Form's libraries


raulbolanos
July 21st, 2009, 03:32 AM
Hi guys,

I need show an exception with a MessageBox but it take place in one project which mustn't use Form libraries. Maybe something like this.


public static void Main()
{
try
{
hallo(4);
}
catch (ArgumentOutOfRangeException ex)
{
MessageBox.Show(ex);
}

}

public static int hallo(int i)
{
int a;
try
{
int[] hola = {1, 2, 3};
a = hola[i];
}
catch (Exception ex){ throw ex; }
return a;
}


Thank you in advance.

Mutant_Fruit
July 21st, 2009, 03:37 AM
If you want to show a MessageBox, use the System.Windows.Forms library, that's why it's there. If you can't use that library, then don't use a MessageBox. You'll just end up duplicating (probably incorrectly) a load of code in System.Window.Forms just to emulate the single line: MessageBox.Show ("blah")

HanneSThEGreaT
July 21st, 2009, 04:30 AM
You could try to use the MessageBox API. But even that would also be an overkill. still worth a shot though :)

raulbolanos
July 21st, 2009, 04:36 AM
Yes, it works perfectly!

Thank you very much.