CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Location
    Stuttgart, Germany
    Posts
    56

    Question Use MessageBox without using Form's libraries

    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.

    Code:
    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.

  2. #2
    Join Date
    May 2007
    Posts
    1,546

    Re: Use MessageBox without using Form's libraries

    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")
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Use MessageBox without using Form's libraries

    You could try to use the MessageBox API. But even that would also be an overkill. still worth a shot though

  4. #4
    Join Date
    Mar 2009
    Location
    Stuttgart, Germany
    Posts
    56

    Red face Re: Use MessageBox without using Form's libraries

    Yes, it works perfectly!

    Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured