Usercontrol properties - Am I missing something??? 
Author Message
 Usercontrol properties - Am I missing something???

I am writing a usercontrol in vb and would like to add a property which
shows up on the property browser as combo box. I know how to add items such
as the color picker etc. but I can't find anyhting that will allow me to add
a list of n options to a property.

Am I missing something? Any help much appreciated.

Cheers

Apologies if this has already been discussed in this newsgroup.



Tue, 13 Jan 2004 02:40:20 GMT  
 Usercontrol properties - Am I missing something???
Heres a little piece of code that I recently started working on.

Add a textbox named text1 to a blank control, then paste this in.

You'll see the new property : TEST
and the values supplied in the TespProp enum
inside the properties window when dropped on a form.

D.

Option Explicit
Const m_def_Test = 0
Dim m_Test As TestProp

Public Enum TestProp
   [Numeric Only] = 1
   [Credit Card]
   [Phone Number]
   [Proper Name]
   [5 Digit Zip Code]
   [9 Digit Zip Code]
End Enum

Public Property Get Test() As TestProp
   Test = m_Test
End Property

Public Property Let Test(ByVal New_Test As TestProp)
   m_Test = New_Test
   PropertyChanged "Test"
End Property

Private Sub Text1_KeyPress(KeyAscii As Integer)

    Dim x%

    Select Case Test
        Case TestProp.[5 Digit Zip Code]
            If (KeyAscii < vbKey0 Or KeyAscii > vbKey9) Or Len(Text1.Text) >
4 Then
                KeyAscii = 0
            End If

        Case TestProp.[9 Digit Zip Code]
            If (KeyAscii < vbKey0 Or KeyAscii > vbKey9) Or Len(Text1.Text) >
8 Then
                KeyAscii = 0
            End If

        Case TestProp.[Credit Card]
             x = Text1.SelStart

            If Len(Text1.Text) = 19 Then
                Select Case Text1.SelStart
                    Case 4, 9, 14
                        x = x + 1
                    Case Else
                End Select

                Text1.SelStart = x

                If Mid$(Text1.Text, x + 1, 1) <> "" Then
                    Text1.Text = Left(Text1.Text, Text1.SelStart) &
Right$(Text1.Text, (Len(Text1.Text) - 1) - Text1.SelStart)
                    Text1.SelStart = x
                End If

            End If

            If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) And
(Len(Text1.Text) <= 18) Then

                Select Case Text1.SelStart
                    Case 4, 9, 14

                        If Mid$(Text1.Text, Text1.SelStart, 1) <> "-" Then
                            Text1.Text = Text1.Text & "-"
                        End If
                        Text1.SelStart = x + 1
                End Select

            ElseIf Len(Text1.Text) <= 19 And KeyAscii = vbKeyBack Then
            Else
                KeyAscii = 0
            End If

            Debug.Print Format(Text1.Text, "####-####-####-####")
            Debug.Print Format(Text1.Text, "0000-0000-0000-0000")

        Case TestProp.[Numeric Only]
        Case TestProp.[Phone Number]
        Case TestProp.[Proper Name]
    End Select

End Sub

Private Sub UserControl_InitProperties()
   m_Test = m_def_Test
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
   m_Test = PropBag.ReadProperty("Test", m_def_Test)
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
   Call PropBag.WriteProperty("Test", m_Test, m_def_Test)
End Sub


Quote:
> I am writing a usercontrol in vb and would like to add a property which
> shows up on the property browser as combo box. I know how to add items
such
> as the color picker etc. but I can't find anyhting that will allow me to
add
> a list of n options to a property.

> Am I missing something? Any help much appreciated.

> Cheers

> Apologies if this has already been discussed in this newsgroup.



Tue, 13 Jan 2004 02:55:09 GMT  
 Usercontrol properties - Am I missing something???
In some few words: the property-type has to be an enum.


Tue, 13 Jan 2004 05:07:17 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Access Runtime - Am I Missing Something?

2. AM I missing something - Sum and Cumulative Sum

3. VBA For Dummies --- Am I missing something here?

4. Am I missing something?

5. Am I missing something?

6. Am I missing something incredibly easy?

7. Am I missing something in the DHTML Editor?

8. Undraggable controls: Am I Missing something???

9. Am I missing Something?

10. Am I missing something?

11. Am I missing something here ...? Instr Function

12. RegEx: Am I missing something?

 

 
Powered by phpBB® Forum Software