I created a custom UITypeEditor.
It is worling properly ... BUT :
I want to refresh the Property in the calling Control while using this Editor. My Editor is a SliderEditor and while moving the Slider the Property should change it's value.
My code is :
Public Class SliderEditor
Inherits UITypeEditor
Public Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle
Return UITypeEditorEditStyle.DropDown
End Function
Private myContext As System.ComponentModel.ITypeDescriptorContext = Nothing
Private myPropDescriptor As System.ComponentModel.PropertyDescriptor = Nothing
Private Sub editControl_Changed(ByVal sender As Object, ByVal aktPosition As Single)
myPropDescriptor.SetValue(myContext.Instance, aktPosition)
System.ComponentModel.TypeDescriptor.Refresh(myContext.Instance)
End Sub
Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object
If value.GetType() IsNot GetType(Double) _
AndAlso value.GetType() IsNot GetType(Single) _
AndAlso value.GetType() IsNot GetType(Integer) Then
Return value
Exit Function
End If
Dim editorService As IWindowsFormsEditorService = DirectCast(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService)
Dim editControl As New RMBaseSlider()
AddHandler editControl.SliderPositionChanged, AddressOf editControl_Changed
myContext = context
myPropDescriptor = context.PropertyDescriptor
Dim pMinMax As Object = context.PropertyDescriptor.Attributes(GetType(PropertyLimitsAttribute))
If pMinMax IsNot Nothing Then
Dim myAttribute As PropertyLimitsAttribute = pMinMax
editControl.Minimum = myAttribute.minValue
editControl.Maximum = myAttribute.maxValue
Else
editControl.Minimum = 0.0
editControl.Maximum = 5.0
End If
editControl.Schrittweite = Math.Ceiling(editControl.Maximum - editControl.Minimum) / 100
editControl.ShowStepButtons = True
editControl.Ausgabe = CSng(value)
editControl.Width = 210
editControl.Height = 30
editorService.DropDownControl(editControl)
RemoveHandler editControl.SliderPositionChanged, AddressOf editControl_Changed
If value.GetType() Is GetType(Double) Then
Return CDbl(editControl.Ausgabe)
Exit Function
ElseIf value.GetType() Is GetType(Single) Then
Return CSng(editControl.Ausgabe)
Exit Function
ElseIf value.GetType() Is GetType(Integer) Then
Return CInt(editControl.Ausgabe)
Exit Function
Else
Return value
End If
Return editControl.Ausgabe
End Function
Public Overrides Function GetPaintValueSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return False
End Function
End Class
What I have tried:
Inside my Code I connected the Eventhandler from the RMBaseSlider-Control to the SliderEditor-Method "editControl_Changed".
This works when I use the code-line " System.ComponentModel.TypeDescriptor.Refresh(myContext.Instance)
" because the Property-Grid from the calling Control is now completly repainted. But also the SliderEditor is closed :(
What I want to have is that the value inside the calling Control changes while moving the Slider.
Is there any way to achieve that goal ?
I don't have any additional idea in the Moment ... :(