2

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!

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user2320462
  • 259
  • 3
  • 9

2 Answers2

1

Create the form with the appropriate controls, etc. Then add a static method to the class that handles all the messy bits - creating an instance (if necessary), setting properties, etc.

I wish I could write more on this, but it's pretty simple stuff. Just call MyCustomBox.ShowMessage() or whatever you call the static method.

Corey
  • 15,524
  • 2
  • 35
  • 68
1

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");
Alessandro D'Andria
  • 8,663
  • 2
  • 36
  • 32