There is often such a problem online: How to add a "..." button or drop-down list box when you display it in the properties window, and then edit the value of this property by a custom editor. I will give a common example, assuming that your property represents a path, you want to have a "..." button when displayed in the Properties window, click the Directory Selection dialog, you can pick the folder directly.
First, to write a Editor class, inherit from system.drawing.design.uitypeEditor:
Imports System.Security.Permissionsimports System.ComponentModelimports System.drawing.Designimports System.Windows.Forms
Public class patheditor inherits uitypeEditor
.ShowNewFolderButton = False .Description = "Choose the folder of" & _ context.PropertyDescriptor.DisplayName .SelectedPath = CStr (value) .RootFolder = Environment.SpecialFolder.MyComputer .ShowDialog () Return .SelectedPath End With End Using End Function
END CLASS
When implementing this class, several methods of UITYPEEDITOR should be rewritten. The getEditStyle method returns a number indicating that the editor uses an external editor (display "...", and pops up) or use a drop-down list. This example we use an external editor. If you don't rewrite this method, you will not have any special editing methods by default. GetPaintValeSupported method Returns whether to support the attribute editor redraw. We often see the editor of the color property directly display color, the editor of the icon properties can display the thumbnail of the icon, etc., all through this function. Here we don't need it. The last EditValue property is the specific definition of editing methods. We need a directory Select dialog to edit your directory, you can create it in your code. The value parameter represents the value of the attribute before editing this property, and the Contex parameter provides some information about the property itself. After writing, we can bind this editor to our properties. Used is EditoAttribute, as follows:
This EditoAttribute should accept two parameters, one is the type of Editor class, just that the class we have written, one must be the type of UITYPEEDITOR itself and can be obtained with the GetType operator. Your properties are now editing with custom editors. Figure:
After clicking that editing button, pop up the editor:
There are also many editors, such as editing of the collection attribute, editor editing the custom structure, etc., can be freely designed, and then write Editor to design your own properties.