views:

524

answers:

1

Hello guys,

I have a question about extending a custom control which inherits from UserControl.

public partial class Item : UserControl
{
    public Item ()
    {
        InitializeComponent();
    }
}

and I would like to make a control which inherits from Item

sg like that

public partial class ItemExtended : Item
    {
       public ItemExtended():base()
        {
            InitializeComponent();
        }
    }

This works perfectly of course and the heritage works but my problem is in the designer

I just cannot open this ItemExtended in Design....

it says : Constructor on Type "Item" not found.

Does sy have an explanation?

is the best way to do it?

Thx

I'm of course using c# on .NET Winform :)

A: 

Hi, you invoke InitializeComponent() twice with calling InitializeComponent() on the very derived usercontrol.

This may lead to problem.

And there is some help property callad IsDesign or Design (something similar) of UC, which helps to avoid unnecessary UI operations on design time (in VS).

Edit: it is DesignMode. You can avoid to run RT functions by Design. Like if (!this.DesignMode) InitializeComponents();

You can also check this forumpost. http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=41254

can you be more precies about this isDesign/Design stuff?
It's called DesignMode, iirc. if (DesignMode) ...
Simon Svensson
Thx you guys for your answers