Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :
VB
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
        ' überprüfen, ob der Wert zu verarbeiten ist
        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

        ' Service für die Anzeige des DropDown-Editors abrufen
        Dim editorService As IWindowsFormsEditorService = DirectCast(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService)

        ' Instanz des UserControls erzeugen
        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
        ' Wert(e) übergeben
        editControl.Schrittweite = Math.Ceiling(editControl.Maximum - editControl.Minimum) / 100
        editControl.ShowStepButtons = True
        editControl.Ausgabe = CSng(value)
        editControl.Width = 210
        editControl.Height = 30
        ' UserControl als Drop-Down-Editor anzeigen
        editorService.DropDownControl(editControl)

        RemoveHandler editControl.SliderPositionChanged, AddressOf editControl_Changed

        ' den geänderten Wert im ursprünglich übergebenen Format zurückgeben
        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
        ' eingestellten Wert zurückgeben
        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 ... :(
Posted
Updated 28-Sep-16 4:17am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900