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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set usercontrol property

Status
Not open for further replies.

aldair

Programmer
Joined
Nov 21, 2003
Messages
4
Location
IT
hello!
i had problem with property in my user control! i use:
i hade this code in my User contrlo

Private WithEvents mFont As StdFont

Private Sub UserControl_Initialize()
' FONT
Set mFont = New StdFont
Set UserControl.Font = mFont
Set mTEXTBOX.Font = mFont
End Sub

Public Property Get Font() As StdFont
Set Font = mFont
End Property

Public Property Set Font(mnewFont As StdFont)
Set mFont = mnewFont

Set mTEXTBOX.Font = mFont
Set UserControl.Font = mFont

PropertyChanged "Font"
End Property

Private Sub mFont_FontChanged(ByVal PropertyName As String)
Set UserControl.Font = mFont
Set mTEXTBOX.Font = mFont
Refresh

End Sub

now, in project windows it works, i mean it change the font, when i lunch the project it comes back to original font!
any suggestion why it happens?

(i have the same the result with another proerty! i chenge it in project, it come back to default valure in exe!)
 
you should have something like this also(which saves your settings)...

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)

With PropBag
.WriteProperty "Font", mFont
End With

End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)

With PropBag
mFont = .ReadProperty("Font", "your default font")
End With
End Sub

 
i've post:

Private Sub UserControl_Initialize()
Set mFont = New StdFont

Set mBAG = New PropertyBag
UserControl_ReadProperties mBAG
...
end sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
With PropBag
.WriteProperty "Font", mFont
End With
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
With PropBag
mFont = .ReadProperty("Font", mFont)
End With
End Sub


but the line:
mFont = .ReadProperty("Font", mFont)

causes error:
run-time error '91'
Object Variable or block variable With not setted

!?!
 
You'll need a default, I think. Maybe mfont is still "Nothing" and a font object does not exist in the properties cache.

Greetings,
Rick
 
> mFont = .ReadProperty("Font", mFont)

.ReadProperty(&quot;Font&quot;, mFont)<-- mFont is a default setting if the propertybag cannot return a value or nothng has been written to the propertybag, try using your variable: StdFont for the default value.

Have a look at this example I posted on P.S.C...

 
...!!!....
it was so easy!!!!
thenks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top