Search code examples
c#winformstimestampmessagebox

Display All MessageBox in Program with TimeStamp method


Is there a way I can programatically set all MessageBoxes with a timestamp tacked on the end of the msg string.

private string DataTimeMsgBox()
{
    return DateTime.Now.ToString();
}
MessageBox.Show("Cannot Pass An Empty Textbox" + " " + DataTimeMsgBox());

Above Is not what I'm looking for, but this is

MessageBox.Show("Message with timestamp") 

Result:

"Message with timestamp 00/0000/00 12:00"

Solution

  • Create your own helper method:

    private void ShowMessage(string message)
    {
        MessageBox.Show(message + " " + DateTime.Now.ToString());
    }
    

    Call this method instead of calling MessageBox.Show.