
Adding Properties to Controls via My Control
I am wanting to add properties to controls that exist on a form just like to
tooltip works. Has anyone done this that can help me with this? THe type
of project that I have is a WIndwos Control Library with a component class.
I have implemented the IExtenderProvider and have my code in the CanExtend
function. Here is a code snippet of what I have:
<ProvideProperty("Restrictor", GetType(String))> _
Public Class Restrictor
Inherits System.ComponentModel.Component
Implements IExtenderProvider
Dim ptyRestrict As String
Dim ptyRestrictorChoice As Hashtable
Private ActiveControl As System.Windows.Forms.Control
#Region " Component Designer generated code "
<DefaultValue("True")> _
Public Function GetRestrictor(ByVal MyControl As Control) As String
Dim MyText As String = CStr(ptyRestrictorChoice(MyControl))
If MyText Is Nothing Then
MyText = String.Empty
End If
Return MyText
End Function
Public Sub SetRestrictor(ByVal MyControl As Control, ByVal Value As String)
If Value Is Nothing Then
Value = String.Empty
End If
If Value.Length = 0 Then
ptyRestrictorChoice.Remove(ptyRestrictorChoice)
RemoveHandler MyControl.Enter, AddressOf OnControlEnter
RemoveHandler MyControl.Leave, AddressOf OnControlLeave
Else
ptyRestrictorChoice(MyControl) = Value
AddHandler MyControl.Enter, AddressOf OnControlEnter
AddHandler MyControl.Leave, AddressOf OnControlLeave
End If
If MyControl Is ActiveControl Then
MyControl.Invalidate()
End If
End Sub
Public Function CanExtend(ByVal extendee As Object) As Boolean Implements
System.ComponentModel.IExtenderProvider.CanExtend
If TypeOf extendee Is Control And Not TypeOf extendee Is Restrictor Then
Return True
Else
Return False
End If
End Function
Private Sub OnControlEnter(ByVal sender As Object, ByVal e As EventArgs)
ActiveControl = CType(sender, Control)
ActiveControl.Invalidate()
End Sub
Private Sub OnControlLeave(ByVal sender As Object, ByVal e As EventArgs)
If sender Is ActiveControl Then
ActiveControl = Nothing
ActiveControl.Invalidate()
End If
End Sub
End Class
This is the example that i found from microsofts help area.
THanks in advance for the help.
Paul Gorman ><>