CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2004
    Posts
    239

    Unhappy [2008] Type Converter Question

    I have written a Type Converter for a TrackBar. I was wondering if there is any way to get the value being changed in the Dropdown so I can update the PropertyGrid item value dynamically instead of just at the end?

    Here is the Type Converter code:

    Code:
    Imports System.Windows.Forms.Design
    
    Public Class Slider
        Private editorService As IWindowsFormsEditorService
    
        Private m_Value As Integer
    
        Public Property Value() As Integer
            Get
                Return m_Value
            End Get
            Set(ByVal value As Integer)
                m_Value = value
            End Set
        End Property
    
        Public Sub New()
            ' This call is required by the Windows Form Designer.
            InitializeComponent()
    
            ' Add any initialization after the InitializeComponent() call.
            tbSlider.LargeChange = 25
            tbSlider.SmallChange = 10
            tbSlider.TickFrequency = 15
            tbSlider.Maximum = 255
            tbSlider.Minimum = 0
            tbSlider.Size = Me.Size
    
            Me.editorService = editorService
    
        End Sub
    
        Public Sub New(ByVal MyValue As Integer, ByVal MyLargeChange As Integer, ByVal MySmallChange As Integer, ByVal MyTickFrequency As Integer, ByVal MyMinimum As Integer, ByVal MyMaximum As Integer, ByVal editorService As IWindowsFormsEditorService)
            ' This call is required by the Windows Form Designer.
            InitializeComponent()
    
            ' Add any initialization after the InitializeComponent() call.
            tbSlider.LargeChange = MyLargeChange
            tbSlider.SmallChange = MySmallChange
            tbSlider.TickFrequency = MyTickFrequency
            tbSlider.Maximum = MyMaximum
            tbSlider.Minimum = MyMinimum
            tbSlider.Value = MyValue
    
            Me.editorService = editorService
    
        End Sub
    
        Private Sub tbSlider_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbSlider.ValueChanged
    
            m_Value = CInt(tbSlider.Value)
        End Sub
    End Class
    Here is the Property Code:


    Code:
        <System.ComponentModel.Category("Appearance"), _
        System.ComponentModel.DefaultValue("200"), _
        System.ComponentModel.Editor(GetType(OpacitySliderEditor), GetType(System.Drawing.Design.UITypeEditor)), _
        System.ComponentModel.Description("Value that represents a change in the Opacity or transparency of the control.")> _
        Public Property Opacity() As Integer
            Get
                Return m_Opacity
            End Get
            Set(ByVal value As Integer)
                m_Opacity = value
                SetBkImage()
                Me.Invalidate()
            End Set
        End Property

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: [2008] Type Converter Question

    I don't know if you can get the dropdown to change positions according to the slider. Might be easier to use a textbox or label control, though.

    Isn't there a .value of something for the slider properties?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Nov 2004
    Posts
    239

    Unhappy Re: [2008] Type Converter Question

    I don't want the DropDown to change, just to be able to update the associated PropertyGrid value as the TrackBar moves...

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: [2008] Type Converter Question

    Use the CLICK event of the slider (as previously mentioned).

    You can create an event that fires automatically
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Nov 2004
    Posts
    239

    Unhappy Re: [2008] Type Converter Question

    There is no Click event, but I am trapping the ValueChanged() event and setting the Value. The problem is that this Value isn't passed back to the PropertyGrid until the slider has closed...

    Code:
        Private Sub tbSlider_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbSlider.ValueChanged
    
            m_Value = CInt(tbSlider.Value)
        End Sub

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: [2008] Type Converter Question

    No MouseDown, or MouseUp? I thought that was a way to trap movement (don't have vs here)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Nov 2004
    Posts
    239

    Unhappy Re: [2008] Type Converter Question

    The problem has to be in the TypeEditor code. Right now once the DropDown in the TypeEditor has control, the PropertyGrid value doesn't get updated until the DropDown completes...

    Here's the TypeEditor Code:

    Code:
    Imports System.ComponentModel
    Imports System.Drawing.Design
    Imports System.Windows.Forms.Design
     
    Public Class cOpacitySlider
        Friend Class OpacitySliderEditor
            Inherits UITypeEditor
            Private editorService As IWindowsFormsEditorService
     
            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
                If Not (provider Is Nothing) Then
                    editorService = _
                    CType(provider.GetService(GetType(IWindowsFormsEditorService)),  _
                    IWindowsFormsEditorService)
                End If
     
                If Not (editorService Is Nothing) Then
                    Dim selectionControl As New Slider(CType(value, Integer), 25, 10, 15, 0, 255, editorService)
     
                    editorService.DropDownControl(selectionControl)
     
                    value = selectionControl.Value
                End If
     
                Return value
     
            End Function
        End Class
    End Class

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: [2008] Type Converter Question

    See if you can use Invalidate. Maybe the slider? If nothing else, then the form itself?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured