Shahar Mosek
Shahar Mosek

Reputation: 1982

Run different code in VS designer

I have a class that inherits the Windows Forms Combobox. The class should do extra work when items are added, but there is no such event. Therefore, I have added methods to add and clear items, which do the extra work. To avoid developers accessing the Items directly and adding to them, I have overloaded the Items property to throw an exception.

This all works fine, except in the VS designer. The designer tries to access the Items property, gets the exception and shows an error.

Is there a defined constant for when the VS designer compiles the code? This seems like it would be best suited to the task.

Upvotes: 0

Views: 51

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499830

Are you looking for the Control.DesignMode property? To be honest, it doesn't sound great from a design point of view to have a ComboBox subclass which can't be used as a normal ComboBox... and if you've really just hidden (or shadowed) the Items property with another one, then anyone referring to it as a ComboBox will have access to the original Items property anyway. It's unclear what you're really trying to do here.

Upvotes: 1

Related Questions