Thanks for your input peeps.
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
On Aug 29, 8:06 am, "Patrice" <http://www.chez.com/scribe/wrote:
Use a property instead of a public variable
:http://msdn2.microsoft.com/en-us/lib...57(VS.80).aspx
You may want to read the whole spec at least once so that you know what is
available :http://msdn2.microsoft.com/en-us/lib...37(vs.80).aspx
---
Patrice
"tc" <t...@idcodeware.co.uka écrit dans le message de news:
O02njKj6HHA....@TK2MSFTNGP06.phx.gbl...
I'm trying to put together a small control. It's not, but for arguments
sake, let's say it's a progress bar.
The user will make a change to a setting, lets call it 'value'.
I want to trap the change of the public variable in the controls code so
I
can act on that change.
How would I do that?
To build on Patrice's statements:
I would change the public variable (which should almost always be
avoided imo) into a public property. In the Set accessor I would
inspect the value to see if it is different than the current value and
if so I would fire off the necessary events.
Something like (untested):
//////////////////////
Public Class TheClass
Public Property MyProperty() As String
Get
Return _MyProperty
End Get
Set(ByVal value As String)
Dim isDifferent As Boolean = (value <_MyProperty)
If isDifferent Then OnMyPropertyChanging(EventArgs.Empty)
_MyProperty = value
If isDifferent Then OnMyPropertyChanged(EventArgs.Empty)
End Set
End Property
Private _MyProperty As String = ""
Public Event MyPropertyChanging As EventHandler
Public Event MyPropertyChanged As EventHandler
Protected Overridable Sub OnMyPropertyChanging(ByVal e As
EventArgs)
RaiseEvent MyPropertyChanging(Me, e)
End Sub
Protected Overridable Sub OnMyPropertyChanged(ByVal e As
EventArgs)
RaiseEvent MyPropertyChanged(Me, e)
End Sub
End Class
////////////////////
That way you have events that can notify any listeners both before and
after the change to the property occurs.
Thanks,
Seth Rowe