|
-
September 25th, 2009, 06:14 PM
#1
[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
-
September 25th, 2009, 08:20 PM
#2
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?
-
September 29th, 2009, 01:13 PM
#3
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...
-
September 29th, 2009, 05:28 PM
#4
Re: [2008] Type Converter Question
Use the CLICK event of the slider (as previously mentioned).
You can create an event that fires automatically
-
September 29th, 2009, 06:24 PM
#5
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
-
September 29th, 2009, 11:46 PM
#6
Re: [2008] Type Converter Question
No MouseDown, or MouseUp? I thought that was a way to trap movement (don't have vs here)
-
September 30th, 2009, 11:57 AM
#7
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
-
September 30th, 2009, 01:49 PM
#8
Re: [2008] Type Converter Question
See if you can use Invalidate. Maybe the slider? If nothing else, then the form itself?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|