About User Controls

  • Thread starter Thread starter Raj
  • Start date Start date
R

Raj

Hi,

I have created a Windows 'user control' in C#.NET. This user control defines
several public 'properties' that the outer world can use to tweak the
behavior of the user control. However, whenver I drag the user control to a
Form, I noticed that the 'Windows Form Designer generated code' contains
several auto generated statments to initialize the 'properties' that are not
proper. This causes the Form designer to get corrupt and shows a designer
error in design mode. This happens each time I build the code!!!

The property that is defined is
public object[] UserControlData
{ set { }

get { }

}

and it is getting assigned the foll value due to which it is getting
corrupted:
this.expertTimeline1.UserControlData = new object[0] { new System.Double[]
{

1E+108}, new System.Double[] {1E+108}};


Is there someway to prevent the auto generation of code?
Is there some way to define default values for the properties?
Is there something wrong in the way I am defining the methods?


Thanks & Regards,
Raj
 
Hi,

1.
You could control the designer-code-generation using the
DesignerSerializationVisibility attribute.

MSDN:
http://msdn.microsoft.com/library/e...designerserializationvisibilityclasstopic.asp

2.
Use the DefaultValueAttribute to specify default values the designer would
use.

MSDN:
http://msdn.microsoft.com/library/e...onentModelDefaultValueAttributeClassTopic.asp

3.
Well, you could use the Component.DesignMode property to render contents
only if the component is properly initialized.

Does this address all your issues?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top