Search code examples
c#messagebox

custom single line messagebox


I'm trying to make a custom message box for my application. The problem is, I want to code it in a way so that I can use it as regular message box.

MyCustomBox("My Message");

intead of doing

FormMessage frm = new FormMessage();
frm.message = "My Message";
frm.show();

How can I accomplish this? Thanks!


Solution

  • You can add a static method to FormMessage class

    public static void ShowBox(string message)
    {
        using (FormMessage frm = new FormMessage())
        {
            frm.Message = message;
            frm.ShowDialog();
        }
    }
    

    And then

    FormMessage.ShowBox("My Message");