|
-
May 31st, 2010, 04:34 AM
#1
[RESOLVED] Updating the Visual Studio Properties Window
I'm designing a custom toolbox component. Some of the public properties are interdependent. At present, when the user changes one of these values in the Designer, the dependent value doesn't update until the user clicks on it. Does anyone know how I can "refresh" the Properties window to show the new value of the dependent property?
BB
-
May 31st, 2010, 08:19 AM
#2
Re: Updating the Visual Studio Properties Window
Perhaps you can use the RaiseComponentChanged method of the control designer. I'm not sure if that works but it's worth a try. If you are using a custom designer already you can just call
Code:
Me.RaiseComponentChanged(TypeDescriptor.GetProperties(Me.Control)("PropertyNameHere"), Nothing, Nothing)
I'm trying it now but I can only work on it for 2 minutes every 5/10 minutes so it's not going very fast 
EDIT
It doesn't seem to work 
Here's the code I tried:
Code:
Imports System.ComponentModel.Design
Imports System.Windows.Forms.Design
Imports System.ComponentModel
<Designer(GetType(UserControl1.UserControl1Designer))> _
Public Class UserControl1
Private _Prop As String
Private Event PropChanged As EventHandler
' Main property
Public Property Prop() As String
Get
Return _Prop
End Get
Set(ByVal value As String)
_Prop = value
' raise event when changed
Me.OnPropChanged()
End Set
End Property
' Dependent property
Public Property Prop2() As String
Get
Return Me.Prop
End Get
Set(ByVal value As String)
Me.Prop = value
End Set
End Property
Private Sub OnPropChanged()
RaiseEvent PropChanged(Me, EventArgs.Empty)
End Sub
' Designer
Friend Class UserControl1Designer
Inherits ControlDesigner
' Attach PropChanged event
Public Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
MyBase.Initialize(component)
Dim uc As UserControl1 = DirectCast(Me.Control, UserControl1)
AddHandler uc.PropChanged, AddressOf PropChanged
End Sub
' RaiseComponentChanged to notify a change... Doesn't seem to work :(
Private Sub PropChanged(ByVal sender As Object, ByVal e As EventArgs)
Me.RaiseComponentChanged(TypeDescriptor.GetProperties(Me.Control)("Prop"), Nothing, Nothing)
Me.RaiseComponentChanged(TypeDescriptor.GetProperties(Me.Control)("Prop2"), Nothing, Nothing)
End Sub
End Class
End Class
But it still doesn't update Prop2 until I select it in the property grid. Perhaps there's other methods you can call here to get it to update, but I'm not sure.
Last edited by NickThissen; May 31st, 2010 at 08:23 AM.
-
May 31st, 2010, 11:36 AM
#3
Re: Updating the Visual Studio Properties Window
Thanks for all your effort Nick. I've just started scratching at the surface of the huge area of component design. (In fact, I'm not even sure what a ControlDesigner is for, let alone using one. Presumably that means I'm using the default Designer.)
Anyway, your posting prompted me to have another rummage around in MSDN and this time I luckily found the answer -- the PropertyDescriptor Class. It offers a dozen or so useful methods and properties that affect the Properties Window, for example GetValue, SetValue and CanResetValue. I just tried SetValue out on a simple example and it works as expected. So: Resolved .
-
May 31st, 2010, 12:07 PM
#4
Re: [RESOLVED] Updating the Visual Studio Properties Window
Cool. Just so you know, a ControlDesigner can be used to extend the design-time experience of any custom controls (or UserControls). Things that I have used them for include:
1. Enabled design-time support for many controls, such as a TabControl on a UserControl. Normally, you can't 'control' the TabControl because it is on the UserControl, but by using a custom designer you can get it to respond to, for example, mouse events, and behave almost like it is in run-time. For a good but complex example, see my Wizard control. For an easier example, see my expandable groupbox.
2. Changing the snap lines.
3. Provide 'smart tags' for controls, which appear when you click the [>] icon on the top-right corner.
4. Control how the control is selectable and resizable.
5. Control which control can be parented by (or to, can't remember) this control.
And probably many more I can't remember right now.
You are probably using the default designer yes. If you don't specify a Designer attribute on your class, it uses the default.
-
May 31st, 2010, 06:00 PM
#5
Re: [RESOLVED] Updating the Visual Studio Properties Window
I think the best way (finally, I know something about an attribute) is the RefreshProperties() attribute:
Code:
<System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.All)> Public Property ....
You don't even have to write any handling code.
-
Jun 1st, 2010, 02:57 AM
#6
Re: [RESOLVED] Updating the Visual Studio Properties Window
Cool, I didn't know that, seems like the best option yes.
-
Jun 1st, 2010, 03:12 AM
#7
Re: [RESOLVED] Updating the Visual Studio Properties Window
Perfect, minitech . It's an elegant alternative to the PropertyDescriptor. Hyperresolved . BB
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
|