Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modifying userconcrol on Form (How to??)

Status
Not open for further replies.

tjayvb

Programmer
Sep 23, 2003
3
NL
As a newbie at VB6, I'm building a flashcard application for my son.
(Learning how to read)

I've made a (colorful) Usercontrol.
This exist of a 1: "shape1" and 2. "textlabel1"

This control is placed on a form
Form1.usercontrol1

At runtime I want to modify the textlabel of de usercontrol.
Problem is I can't find a way to do this.

In the watch window I find:
"usercontrol1.object.Controls.Item1.caption"
But by coding this I get an error.

I would say it must be possible to code:
"usercontrol1.textlabel1.text"
or
"usercontrol1.object.Controls.textlabel1.caption"

but no...

What am I doing wrong?

 
If "textlabel1" is a textbox then try

Code:
textlabel1.text = "Some text"

If "textlabel1" is a label then try,

Code:
textlabel1.caption = "Some text"

If it is neither of these control types then what control type is it.



Thanks and Good Luck!

zemp
 
Hi,

The controls that make up your user control are "hidden" from outside of itself so you will need to create a user control property (LET and GET) for the caption.

'Insert code into your usercontrol. Assumes your label is
'named: "label1".

Public Property Get Caption() As String
Caption = Label1.Caption
End Property

Public Property Let Caption(ByVal vNewValue As String)
Label1.Caption = vNewValue
PropertyChanged "Caption"
End Property

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
With PropBag
Label1.Caption = .ReadProperty("Caption", "label")
End With
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
With PropBag
.WriteProperty "Caption", Label1.Caption, "label"
End With
End Sub


'In your app's code you should would use:

usercontrol1.caption = "My caption"

Have a good one!
BK
 
Blacknight,

thank you for this answer.
It did the job.

Now solve the next problems.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top