Show alerts in a Console Application C # [closed]

0


Already notice that maybe my doubt is very primary, but come on ...
I'm doing a console-type project in C #, but I'm having trouble displaying error alerts. What I wanted to do was leave a separate part of the console for alerts, and when the user does something wrong, show that region, otherwise it stays hidden. Someone has done something similar or can give tips on how to show error alerts. I accept other solutions and tips. Right now, thank you all.

    
asked by anonymous 08.08.2017 / 13:49

1 answer

2

Well I'm assuming you're using Windows: You can put the error message in a messgeBox:

Using the

  

System.Runtime.InteropServices;

using System;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{

    class Program
    {
        [DllImport("User32.dll", CharSet = CharSet.Unicode)]

        public static extern int MessageBox(IntPtr h, string m, string c, int type);
        static void Main(string[] args)
        {
            Console.WriteLine("MessageBox de erro");
            Console.ReadLine();
            MessageBox((IntPtr)0, "Erro", "Error", 0);
        }
    }
}

or by using

  

System.Windows.Forms do not forget to add the reference in your   project:

using System;
using System.Windows.Forms;

namespace ConsoleApplication1
{

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("MessageBox de erro");
            Console.ReadLine();
            MessageBox.Show("Erro", "Error");
        }
    }
}
    
08.08.2017 / 14:08