?
Solved

Create a Font Property to a new UserControl

Posted on 2003-03-02
8
Medium Priority
?
942 Views
Last Modified: 2013-12-20
I want to create my own Label Control (like the Label form Form 2.0) and I can't create the Font Property.
After I define the Property FONT, in the Properties Window the Font Property appears, but when I select a Font or a Size, the VB tells me "Invalid property value", and i don't know how to work with FONT Object!!! (i didn't used before)

 The code that i used:

Dim m_BorderColor As OLE_COLOR
Dim m_BorderVisible As Boolean
Dim m_BackColor As OLE_COLOR
Dim m_ForeColor As OLE_COLOR
Dim m_Caption As String

.....................

'----- some other properties
Public Property Get Caption() As String
    Caption = m_Caption
End Property

Public Property Let Caption(ByVal New_Caption As String)
    m_Caption = New_Caption
    PropertyChanged "Caption"
    sDrawLabel
End Property
'---------

'- the font property
Public Property Get Font() As StdFont '(i've tried with                                    IFontDisp and nothing)

'? -> i don't know what to put here!
End Property

Public Property Let Font(ByVal New_Font As StdFont)
'?
End Property
0
Comment
Question by:BlueSky007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 3

Expert Comment

by:DeAn
ID: 8054284
'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
  Set UserControl.Font = Ambient.Font
End Sub

'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  Set UserControl.Font = PropBag.ReadProperty("Font", Ambient.Font)
End Sub

'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  Call PropBag.WriteProperty("Font", UserControl.Font, Ambient.Font)
End Sub

is this any help?
0
 
LVL 3

Expert Comment

by:DeAn
ID: 8054291
this will set the font the same as the form or container it's placed on, like the Label control does.
0
 
LVL 3

Accepted Solution

by:
DeAn earned 120 total points
ID: 8054313
oh, you need this too

Public Property Get Font() As Font
  Set Font = UserControl.Font
End Property

Public Property Set Font(ByVal New_Font As Font)
  Set UserControl.Font = New_Font
  PropertyChanged "Font"
End Property
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:BlueSky007
ID: 8063339
I've tried this code but it said that FONT (in tne Set Font = UserControl.Font): Sub or Function not found!

The Font object is valit, becouse if i type Font. , after DOT appers the properties!

What is the problem? Thanks!
0
 

Author Comment

by:BlueSky007
ID: 8063699
I create a new UserControl with a simple Lable in control and i put the code that you give me, but same error ... Sub or Function not found, in the UserControl_initProperties at Font from Set UserControl.Font = ....

I don't know where is the problem. You've tried this code or you have a sample that works (made be you of course)?

Thanks !
0
 

Author Comment

by:BlueSky007
ID: 8063828
I've tried this code and it works (I don't know how i've done it, but it works fine)

'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
    Set Label1.Font = Ambient.Font
    'Print "Adsfoqwjef"
End Sub

Public Property Get Font() As StdFont
 Set Font = Label1.Font
End Property
Public Property Set Font(ByVal New_Font As StdFont)
 Set Label1.Font = New_Font
 'Print "Adsfoqwjef"
 'PropertyChanged "Font"
End Property

'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
 Label1.Font = PropBag.ReadProperty("Font", Ambient.Font)
End Sub

'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    PropBag.WriteProperty "Font", Label1.Font, Ambient.Font
End Sub

Firs i've tried with UserControl instead the Label1 and work with that too, thank
0
 

Author Comment

by:BlueSky007
ID: 8063839
Thank anyway for for idea!
0
 
LVL 3

Expert Comment

by:DeAn
ID: 8066935
thanx BlueSky007, glad it helped ;)
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question