Adding Properties to Controls via My Control 
Author Message
 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 ><>



Wed, 05 Jan 2005 04:54:35 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Control Properties on Access forms via DAO

2. Accessing Control Properties Via its Handle

3. Indentifying controls in an array via .Tag property

4. setting data control properties via wizard

5. Obtaining control properties via API?

6. How to add/delete controls on reports via code

7. Adding a control via code

8. Controlling Text Control Properties without a Control Array.

9. Windows forms designer automatically adds code that sets properties of custom controls

10. Adding New Properties To The Form Controls

11. Adding a user control property thats a class or structure

12. controls.add and the .container property

 

 
Powered by phpBB® Forum Software