CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    2

    How to handle the messages for controls which created at run time?



    How to handle the messages for controls which created at run time?

    (Include windows stardard control and ActiveX control)

  2. #2
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: How to handle the messages for controls which created at run time?





    Hi,


    I guess, you mean 'events' raised from the controls?

    Only way as i know is to have a member variable of the same type and use set

    method when you create a run-time instance. The varibale should have a module-level (global) scope.


    Ex: Suppose you have a control, StateChangingControl ,that raises some StateChanged(NewState,OldState) event.


    To be able to handle this event you need something like this:


    In the declaration section of Form/Class have a line:

    private WithEvents m_mycontrol as StateChangingControl


    and when you create a new runtime instance use:

    ...

    set m_mycontrol = new StateChangingControl

    ...


    With 'WithEvents' command, if VB detects any events associated with this StateChangingControl , it automatically lists them in the methods combobox.

    You should see the member 'm_mycontrol' in the controls (LHS) combo (on the Editor)and when you select this, you should see the event 'StateChanged' in the methods (RHS) combo . And when you select 'StateChanged' from this list,

    VB will create a stub like:


    private sub m_mycontrol_StateChanged(NewState,OldState)

    end sub

    and the respective types of the params would also be present.


    Try a simple code :

    private withevents m_mytimer as Timer

    and it would work like a timer-control of VB


    I hope it was not a long answer for a not-required topic! :-)


    Ravi



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