This section shows you how to display the attribute values in a pop-up dialog box.
Here we define a user control and set an attribute for the user control. Use the pop-up dialog box to set the attribute value.
Define the ShowPropery Property
The Code is as follows:
[Csharp]
Public partial class UCLab: UserControl
{
Public UCLab ()
{
InitializeComponent ();
}
Private string showpropery;
[Description ("pop-up property")]
[Editor (typeof (ShowTypeDialogEditor), typeof (UITypeEditor)]
Public string ShowPropery
{
Get
{
Return showpropery;
}
Set
{
Showpropery = value;
}
}
Public partial class UCLab: UserControl
{
Public UCLab ()
{
InitializeComponent ();
}
Private string showpropery;
[Description ("pop-up property")]
[Editor (typeof (ShowTypeDialogEditor), typeof (UITypeEditor)]
Public string ShowPropery
{
Get
{
Return showpropery;
}
Set
{
Showpropery = value;
}
}
[Csharp] view plaincopyprint ?}
}
Then we set the pop-up property editor for the property and inherit the UITypeEditor class. The Code is as follows:
[Csharp]
/// <Summary>
/// Pop-up Editor
/// </Summary>
Public class ShowTypeDialogEditor: UITypeEditor
{
Public override UITypeEditorEditStyle GetEditStyle (ITypeDescriptorContext context)
{
If (context! = Null & context. Instance! = Null)
{
Return UITypeEditorEditStyle. Modal; // A ellipsis is displayed.
}
Return base. GetEditStyle (context );
}
Public override object EditValue (ITypeDescriptorContext context, IServiceProvider provider, object value)
{
System. Windows. Forms. Design. IWindowsFormsEditorService editorService = null;
If (context! = Null & context. Instance! = Null & provider! = Null)
{
EditorService = (System. Windows. Forms. Design. IWindowsFormsEditorService) provider. GetService (typeof (System. Windows. Forms. Design. IWindowsFormsEditorService ));
If (editorService! = Null)
{
UCLab uclab = (UCLab) context. Instance;
ShowForm sf = new ShowForm (uclab. ShowPropery );
If (sf. ShowDialog () = DialogResult. OK)
{
Value = sf. Result;
Return value;
}
}
}
// Return base. EditValue (context, provider, value );
Return value;
}
}
/// <Summary>
/// Pop-up Editor
/// </Summary>
Public class ShowTypeDialogEditor: UITypeEditor
{
Public override UITypeEditorEditStyle GetEditStyle (ITypeDescriptorContext context)
{
If (context! = Null & context. Instance! = Null)
{
Return UITypeEditorEditStyle. Modal; // A ellipsis is displayed.
}
Return base. GetEditStyle (context );
}
Public override object EditValue (ITypeDescriptorContext context, IServiceProvider provider, object value)
{
System. Windows. Forms. Design. IWindowsFormsEditorService editorService = null;
If (context! = Null & context. Instance! = Null & provider! = Null)
{
EditorService = (System. Windows. Forms. Design. IWindowsFormsEditorService) provider. GetService (typeof (System. Windows. Forms. Design. IWindowsFormsEditorService ));
If (editorService! = Null)
{
UCLab uclab = (UCLab) context. Instance;
ShowForm sf = new ShowForm (uclab. ShowPropery );
If (sf. ShowDialog () = DialogResult. OK)
{
Value = sf. Result;
Return value;
}
}
}
// Return base. EditValue (context, provider, value );
Return value;
}
}
In this way, you can drag the user control to the interface to set the attributes.