Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Designer properties: adding design time validation to your properties.
 

Designer properties: adding design time validation to your properties.

I would like to add design time validation to a custom property of a user control which is exposed in the UI designer.  I would like that validation to occur at design time.  Any ideas on how to do this?  Is  there an attribute which signals the code value being set should be validated at design time?

The scenario is this: 
The developer drags my user control onto a form.
They set my custom description property (string).
If the description value they entered exceeds 64 chars I would like to through an error at design time.

Thanks
KO

ko712000  Tuesday, September 29, 2009 9:03 PM
Thanks! I will give that a try.
KO
  • Marked As Answer byko712000 Wednesday, September 30, 2009 3:58 PM
  •  
ko712000  Tuesday, September 29, 2009 10:14 PM
I'm unaware of a design-time only way of raising exceptions, so I guess any exception will do.

What you need in the setter of the property is something along these lines:

if (DesignMode)
{
    //Currently in design-mode.  Perform validation.
    if ((value != null) && (value.length > 64))
    {
        throw new ArgumentException();
    }
    someMemberVar = value;
}

MCP
webJose  Tuesday, September 29, 2009 10:01 PM
Thanks! I will give that a try.
KO
  • Marked As Answer byko712000 Wednesday, September 30, 2009 3:58 PM
  •  
ko712000  Tuesday, September 29, 2009 10:14 PM

You can use google to search for other answers

Custom Search

More Threads

• New Button Design VB Express
• Docked/Anchored UserControl in Vista -- child controls don't size properly
• Help with creating a custom designer
• PropertyGrid & UITypeEditor passing a cutom list to a custom editor
• when using codeDomSerializer - how to get the object when openning the designer
• how to create a textbox by clicking a button
• How to Print a form in C#?
• DataColumn property in Component
• User Control Events
• datagridviewcheckboxcolumn question?