Display alerts in an Application Console c#

Asked

Viewed 431 times

0



I warn you that maybe my doubt is too primary, but come on...
I’m doing a c#console project, 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 remains hidden.
Someone has done something similar or can give tips on how to show error alerts. I accept other Solutions and tips.
From now on, thank you all.

  • can be in a messageBox?

1 answer

2


Well, I’m guessing 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 using the

System.Windows.Forms don’t forget to add the reference to 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");
        }
    }
}
  • Man, you handled me perfectly. Thank you so much for the tip.

  • @Ricardoalves Try to better formulate your neighbors, so you don’t have to stay in pending, follow a link to help you - en.stackoverflow.com/help/how-to-Ask

Browser other questions tagged

You are not signed in. Login or sign up in order to post.