. Net WinForm user control development-(6) User Control pop-up property settings

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.