Imports System.ComponentModel Imports System.ComponentModel.Design Imports System.Windows.Forms.Design Imports System.Drawing.Design <ProvideProperty("MyValue", GetType(Control))> _ Public Class SampleControl Inherits Component Implements IExtenderProvider Private mMyValues As Hashtable Public Sub New() mMyValues = New Hashtable() End Sub Function CanExtend(ByVal target As Object) As Boolean Implements IExtenderProvider.CanExtend If TypeOf target Is SampleControl Then Return False ElseIf TypeOf target Is Control Then Return True Else Return False End If End Function Public Function GetMyValue(ByVal ctl As Control) As Sample_ST If mMyValues.ContainsKey(ctl) Then Return mMyValues(ctl) Else mMyValues.Add(ctl, New Sample_ST) Return mMyValues(ctl) End If End Function Public Sub SetMyValue(ByVal ctl As Control, ByVal value As Sample_ST) If Not mMyValues.ContainsKey(ctl) Then mMyValues.Add(ctl, value) End If mMyValues(ctl) = value End Sub <Editor(GetType(Sample_STUITypeEditor), GetType(UITypeEditor))> _ <TypeConverter(GetType(ExpandableObjectConverter))> Public Structure Sample_ST Public Code As Integer Public Name As String Public Family As String Public Overrides Function ToString() As String Return Name + " " + Family End Function End Structure End Class Public Class Sample_STUITypeEditor Inherits UITypeEditor Public Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle Return UITypeEditorEditStyle.DropDown End Function Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object Dim service As IWindowsFormsEditorService = provider.GetService(GetType(IWindowsFormsEditorService)) If (service Is Nothing) Or (value Is Nothing) Then Return value End If Dim power As New SampleControl.Sample_ST power = value Using f As New PowerForm f.txtCode.Text = power.Code f.txtName.Text = power.Name f.txtFamily.Text = power.Family If service.ShowDialog(f) = DialogResult.OK Then power.Code = f.txtCode.Text power.Name = f.txtName.Text power.Family = f.txtFamily.Text End If End Using Return power End Function End Class
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)