How to show the date/time in a modal window?

Asked

Viewed 100 times

0

I have a code below but would like to display the date/time in a modal message box.

using System;

public class Program
{
    public static void Main()
    {
        Console.WriteLine("Hello World");       
        Console.WriteLine("agora são: "+DateTime.Now.ToString());       
        var hstr = DateTime.Now.Minute;
        if (hstr > (30)) {
            Console.WriteLine("agora são: "+DateTime.Now.Hour+1);       
        }
        else
        {
            Console.WriteLine(DateTime.Now.Hour+":00");
            Console.WriteLine(": "+DateTime.Now.Minute);        
        }
    }
}
  • 1

    If a Console Application is outside the scope of the project type in this case it is recommended to use a WPF or Winforms project.

  • 2

    @davidterra Not even. A Winforms or WPF project is nothing more than a "console application" that references some DLL’s.

2 answers

3

You need to prepare your project so it has the necessary resources to call the message box.

Your "Console Application" application does not contain the DLL System.Windows.Forms, therefore, you need to import it into your project.

  1. Go to the project menu and click on add reference Menu projeto - adicionar referencia

  2. Choose in this listing by the Assemblies tab the DLL call System.Windows.Forms Importação da DLL Windows.Forms

  3. Add to code the using of this DLL to use the method MessageBox
    using System.Windows.Forms;

  4. Call the MessageBox with your text
    MessageBox.Show("agora são: " + DateTime.Now.ToString(), "Data/hora atual");

-1

Just to show a message in a modal dialogue is like this:

MessageBox.Show(mensagem);

Browser other questions tagged

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