|
-
Jul 21st, 2008, 05:00 AM
#1
UserControl Let/Get Property as Object
Here's my goal:
Code:
Option Explicit
Private m_txt As TextBox
Public Property Let txt(new_txt As TextBox)
Set m_txt = new_txt
End Property
Public Property Get txt() As Object
Set txt = m_txt
End Property
Now,... i have tried everything but have not be able to figure out how to:
1. get this Property ("txt") to VB's "Properties" box and
2. get list of all TextBox-es on a Form where my UC is located into "Properties" box where "txt" Property is now shown (from 1.; if possible).
Hope this makes sence.
-
Jul 21st, 2008, 05:21 AM
#2
Re: UserControl Let/Get Property as Object
You use Property Set instead of Property Let
-
Jul 21st, 2008, 05:22 AM
#3
Re: UserControl Let/Get Property as Object
 Originally Posted by Merri
You use Property Set instead of Property Let 
That doesn't do anything.
-
Jul 21st, 2008, 05:32 AM
#4
Re: UserControl Let/Get Property as Object
Oh, and both properties must use the same type, ie. Object. You can't use TextBox and Object mixed together.
-
Jul 21st, 2008, 05:33 AM
#5
Re: UserControl Let/Get Property as Object
Yeah, I know. It was a typo 
They are both the same. It still doesn't work.
-
Jul 21st, 2008, 05:50 AM
#6
Re: UserControl Let/Get Property as Object
Humm, I managed to miss the last part of the first post, so now I know what you're trying to do. Nope, you can't get a list to VB IDE properties window. It isn't very easy, I've read of some way to do it but it sounded like it would be just an extra dependency mess.
The best you can do is to define Txt as String, then validate there is a textbox of that same name in ParentControls.
Code:
Option Explicit
Private m_Txt As String
Public Property Get Txt() As String
Txt = m_Txt
End Property
Public Property Let Txt(ByVal NewValue As String)
Dim Ctl As Object
NewValue = LCase$(NewValue)
For Each Ctl In ParentControls
If TypeOf Ctl Is TextBox Then
If LCase$(Ctl.Name) = NewValue Then
m_Txt = Ctl.Name
PropertyChanged "Txt"
Exit For
End If
End If
Next Ctl
End Property
Private Sub UserControl_Initialize()
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Dim Ctl As Object, NewValue As String
NewValue = LCase$(PropBag.ReadProperty("Txt", vbNullString))
For Each Ctl In ParentControls
If TypeOf Ctl Is TextBox Then
If LCase$(Ctl.Name) = NewValue Then
m_Txt = Ctl.Name
Exit For
End If
End If
Next Ctl
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Dim Ctl As Object, NewValue As String
NewValue = LCase$(m_Txt)
For Each Ctl In ParentControls
If TypeOf Ctl Is TextBox Then
If LCase$(Ctl.Name) = NewValue Then
PropBag.WriteProperty "Txt", Ctl.Name
Exit For
End If
End If
Next Ctl
End Sub
-
Jul 21st, 2008, 05:53 AM
#7
Re: UserControl Let/Get Property as Object
Thanks, but that approach is already known to me 
Can you post the link where have you read about it?
-
Jul 21st, 2008, 06:07 AM
#8
Re: UserControl Let/Get Property as Object
Nope, it is quite a long time ago. Another suggestion that I could give is to use a property page, so you can make a combobox or whatever you want yourself.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|