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

    Communicating between forms

    Is there a way to call user-defined functions in other forms via a pointer? I need to close windows that are docked to my main form using a function that creates a sliding effect. I want to point to that function on a mouse click event on the form for all possible open windows with the same function.


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

    Re: Communicating between forms

    If the form's subs are public, you can refer to them directly thus:

    ' In frmCustomer
    public Sub RefreshCustomerDetails()
    '..yadda yadda yadda
    End Sub
    'in frmMain
    Call frmCustomer.RefreshCustomerDetails()




    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    Feb 2001
    Posts
    35

    Re: Communicating between forms

    I don't want to hard code the form names into the main form because I want to be able to add extra forms without having to update the main form. Any suggestions?


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

    Re: Communicating between forms

    Aha - in that case you need "Implements"

    Create a class file called something like: IDockableForm with all the things a dockable form does, but no code filled in.

    '\\ IDockableForm
    '\\ Interface Inhertance class
    public Enum enDockTargets
    enDTLeft = 1
    enDTRight = 2
    enDTTop = 3
    enDTBottom = 4
    End Enum

    public Sub DockToBorder(byval Target as enDockTargets)
    'no code here....
    End Sub




    Now in each for, in the declarations part:

    Implements IDockableForm

    'This will create:
    public Sub IDockableForm_Dock(byval Target as enDockTargets)
    'put actual implementation of the docking behaviour here
    End Sub




    And then in your main code, iterate the Forms collection and if they implement IDockableForm, call the IDockableForm_Dock method.

    Dim frmThis as IDockableForm

    for Each frmThis in Forms
    If Not frmThis is nothing then
    Call frmThis.Dock(enDTLeft )
    End If
    next frmThis




    Read the help on the implements keyword for more info....

    HTH,
    Duncan


    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--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