Set Custom Control Custom Property on Leave event...

ChristinaSeay

Member
Joined
Oct 22, 2008
Messages
14
Programming Experience
Beginner
Ok... here's my setup:

I have a custom usercontrol for a MaskedTextBox.

I have a Custom Property that I created called ErrorString. This is working fine at run time when the control is used.

What I need to be able to do is update that property on the Leave event of the usercontrol.

So:

Public Sub MaskedTextBox_Leave ..... Handles MaskedTextBox.Leave

V_ErrorString = "My error message"

End Sub

I want the custom property I created: MaskedTextBox.ErrorString = V_ErrorString

But it tells me that ErrorString is not a member of MaskedTextBox... how can I do this??
 
Try handling the Leave event like this:
VB.NET:
    Protected Overrides Sub OnLeave(ByVal e As System.EventArgs)
        MyBase.OnLeave(e)
        'Your additional code here
    End Sub
What that does is it overrides the Leave event & makes a call to the Base class' Leave event so it makes it to the control on the form still, but allows you to add additional code as well.
 
Cool! That worked... Thank-you!!!!

I also found something else that seems to as well:
<System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.All)> _
Public Sub MaskedTextBox_Leave..... Handles MaskedTextBox.Leave

Is there any benefit to one of them over the other one?
 
I'm not sure what all System.ComponentModel.RefreshProperties does because I've never used it, but here's what MSDN says about it among other things:
MSDN said:
The RefreshPropertiesAttribute class is used for refreshing the design-time view.
But ultimately you want your code to run when the Leave event happens, so overriding it is really what you want.
 
Back
Top