GER
GER

Reputation: 2032

Show Dialog when entering Design Mode on Winform

I would like to display a reminder when opening and editing a certain form in our project. This would be while in Design Mode in Visual Studio.

I tried putting MessageBox.Show in the constructor, Paint and Load event but Nothing seems to work. Is it even possible?

public Form1()
{
    InitializeComponent();

    if (this.DesignMode)
    {
        MessageBox.Show("Remember to fix the xyz control!");
    }

    if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
    {
        MessageBox.Show("Remember to fix the xyz control!");
    }
}

Upvotes: 1

Views: 875

Answers (1)

Hitesh
Hitesh

Reputation: 3860

You can do it in following way:

Create a base form:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        this.Load += new EventHandler(Form1_Load);
    }

    private void Form1_Load(object sender, System.EventArgs e)
    {
        if (this.DesignMode && LicenseManager.UsageMode == LicenseUsageMode.Designtime)
        {
            MessageBox.Show("Hello");
        }
    }

}

And on the second form on wards where you would like to show the message box, you will just have to inherit it, like below:

public partial class Form2 : Form1
{
    public Form2()
    {
        InitializeComponent();
    }
}

and as soon as you open a form in design time, it will show you message box.

This worked for me, I hope this will help you. :)

Upvotes: 1

Related Questions