TerryStone wrote:
I have created a control that displays a list of items. During design
mode I fill it with junk data using calls from the constructor. So
when I look at a form with the control on, instead of being empty, it
has some content, and this gives a better idea of what the form will
look like when run. During runtime it should be empty to start with,
so I comment out the code in the constructor that fills it with dummy
data.
How can I code the control/form so that the constructor knows it is
being shown in design mode?
You can't.
There is a DesignMode property that tells you whether you are in design
mode, but it is correct only after your control / form has a window
handle, which happens well after it is constructed.
You need to move your dummy-data populating code from your constructor
into an OnLoad routine / Load event handler. In there, the DesignMode
property will return the correct result, and you can suppress
populating your form when not in design mode.