How can I override just one EditValue function of a control while keeping all the other properties of that control available? When I assign a single control to the SelectedObject property of a PropertyGrid I get all the properties of the control. In order to override one property I would like to create a property wrapper class that will show me all the controls as before, including the custom EditValue function. But I find that I must define all properties in the wrapper class, else I only get to see the property with the custom EditValue function. This seems very impractical, there must be an easier way. I need to do this because I want to catch the file name of a BackgroundImage that the user can specify. The code to catch the name works fine, here it is for good measure:
Friend Class CatchFileName : Inherits UITypeEditor
Public Overrides Function GetEditStyle(context As ITypeDescriptorContext) As UITypeEditorEditStyle
Return UITypeEditorEditStyle.Modal
End Function
Public Overrides Function EditValue(context As ITypeDescriptorContext,
provider As IServiceProvider, value As Object) As Object
Dim ofd As New OpenFileDialog() With {.Filter = "Image Files|*.bmp;*.jpg;*.jpeg,*.gif;*.png;*.ewf;*.wmf;*.ico"}
If (ofd.ShowDialog() = DialogResult.OK) Then
DirectCast(context.Instance, FormPropertiesWrapper)._BackgroundImageName =
Path.GetFileName(ofd.FileName) ' Strip path
Return Image.FromFile(ofd.FileName)
End If
Return MyBase.EditValue(context, provider, value)
End Function
End Class
<Description("Defines a form's background image."), Category("Display")>
<Editor(GetType(CatchFileName), GetType(System.Drawing.Design.UITypeEditor))>
Public Property BackgroundImage() As Image
Get
Return _Form.BackgroundImage
End Get
Set(ByVal Value As Image)
_Form.BackgroundImage = Value
End Set
End Property
_Form is declared as Form in the wrapper class FormPropertiesWrapper