Auxiliary
Auxiliary

Reputation: 2757

Using an event only in Designer View before run time in Visual Studio

I guess this is a really odd and rare question!!

I've made a certain Label control that inherits the System.Windows.Forms.Label object and thus becomes visible and usable in the designer view. When I drag the label to a form and Visual Studio creates an instance of it, I want it to open an input box and ask me what it's text should be. I overrided the OnCreateControl event and it's working but the problem is that the same thing happens when I run the program, but I just want it to work in the designer view before run time. How should I check/avoid the situation?

Here is the code:

protected override void OnCreateControl()
{
        base.OnCreateControl();
        this.Text = Microsoft.VisualBasic.Interaction.InputBox("Enter text: ");
}

Upvotes: 1

Views: 433

Answers (1)

abc
abc

Reputation: 2437

Use the property DesignMode to find out, whether the Component is designed at the moment or not:

protected override void OnCreateControl()
{
   base.OnCreateControl();
   if (DesignMode)
        this.Text = Microsoft.VisualBasic.Interaction.InputBox("Enter text: ");
}

Upvotes: 3

Related Questions