I have my own control that inherits from Label. When I drop it on a
form, it defaults the object Name to MyLabel1 and the Text to MyLabel1.
I'd like the control to automatically rename itself if it detects, at
design time, the Text property changes; e.g.
private sub MyLabel_TextChanged.... handles Me.TextChanged
if me.Name.StartsWith( "MyLabel") then
me.Name = Me.Text (minus spaces)
end if
end sub
Is this possible?
mnadig - 25 May 2006 00:13 GMT
I found the answer:
Import system.componentmodel
in text changed event:
If Me.DesignMode Then
Dim nameProp As PropertyDescriptor =
TypeDescriptor.GetProperties(Me)("Name")
nameProp.SetValue(Me, "lbl" + FixTextForName(Me.Text))
end if
(where fixTextForName strips out invalid chars for name prop)