views:

34

answers:

2

I have a UserControl that does some cool video capture stuff. Now I slapped that control on a form - and it starts working right away, even in design time! That's very gratifying and all to see it working, but it's kind of annoying at design time, and it slows me down. I know that the UserControl is effectively in run-time when it's being used on another form/control at design time, but I'd like to be able to shut it off when it's not in an actual running app.

What's the best way to do this?

+2  A: 

Put something like this code in your control:

if(DesignMode)
   return;

DesignMode is the property that tells you you're running in the designer.

Coding Gorilla
+2  A: 

UserControl has a property called DesignMode - you can just jump out of any of the control logic if this is true.

Alternatively, if the design approach of your project fits it, you could implement binding on it, port all the working logic out to a non-UI controller class, and only set the controller DataSource in the constructor. The designer usually realises it can't anticipate what the instance assigned to it is going to be, so doesn't try.

Tom W