CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2001
    Posts
    5

    Exposing Activex properties

    Hi:

    How can I expose a property like Font of a constituent control in Visual Basic which itself is a control?

    Thanks



  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Exposing Activex properties


    'are you looking for something like this?
    'A user control, named myCtrl. A textbox in it (but you may use
    'wahatever you want)
    'Warning: code may have a bug (did not completely tested)
    '************usercontrol CODE:************

    option Explicit

    private m_Font as stdole.StdFont

    public property get Font() as stdole.StdFont
    set Font = m_Font
    End property

    public property let Font(byval vNewValue as stdole.StdFont)
    'check the vNewValue, if ok, assing it to module variable
    set m_Font = vNewValue
    'then assign module variable to your control
    '...
    'then confirm changed property
    PropertyChanged = Font
    End property

    private Sub UserControl_Initialize()
    set m_Font = new stdole.StdFont
    End Sub

    private Sub UserControl_Terminate()
    set m_Font = nothing
    End Sub

    '************ ************
    'Test: standard exe, 1 form, 1 myctrl on it and one command button
    '************Form1 CODE************

    option Explicit

    private Sub Form_Load()
    'first way to use: passing from a stdOle variable

    Dim myF as stdole.StdFont
    set myF = new stdole.StdFont

    With myF
    .Name = "Courier new"
    .Bold = true
    .Italic = false
    .Size = 12
    End With
    myctrl.Font = myF
    MsgBox myctrl.Font.Name & "; size=" & myctrl.Font.Size

    End Sub

    private Sub Command1_Click()
    'secon way to use: directly with Font property of the control
    With myctrl
    .Font.Bold = false
    .Font.Name = "Arial"
    End With
    MsgBox "Font Bold = " & myctrl.Font.Bold & "; Font Name= " & myctrl.Font.Name
    End Sub




    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Exposing Activex properties

    You can't use the same name if your user control has a font itself. However, if for example you had a label called lblHeader and wanted to set/get the font for that you could have:

    public property get HeaderFont() as StdFont
    set HeaderFont = lblHeader.Font
    End property

    public property set HeaderFont(NewFont as StdFont)
    set lblHeader.Font = NewFont
    End property




    HTH,
    D.

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured