| 
| 
HOWTO: Implement "What's This?" Help in ActiveX Control
ID: Q192744
 
 |  The information in this article applies to:
 
 
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions  5.0, 6.0
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version  4.0
 
 
 SUMMARY
This article demonstrates two methods of implementing "What's This?" Help
on an ActiveX Control created in Visual Basic. Adding this feature to your
control allows your users to quickly access the appropriate Help topics for
your control.
 
 MORE INFORMATION
An ActiveX control can have its own helpfile and help information for the
contained controls. As per encapsulation rules of COM, it is recommended to
have separate help system for a UserControl. However, in some cases, it is
appropriate to inherit the help from the client form in which the ActiveX
control is sited. This article describes both of these methods.
 Method 1: Using Separate Help System for the UserControlIf the UserControl has its own helpfile, then this method is well suited.
 Step-by-Step ExampleStart a new ActiveX Control project. UserControl1 is created by default.
 
 Place three controls onto the UserControl.
 
 Select Project1 Properties from the Project menu. On the General tab,
   specify the help file in the Help File Name field.
 
 For each control on UserControl1, change the WhatsThisHelpId to a valid
   value for your help file. Close all open windows.
 
 Select Add Project from the Project menu to add a new Standard EXE
   project. Project2 is created by default.
 
 Place UserControl1 onto Form1. Change the BorderStyle property of Form1
   to Fixed Single. Set the WhatsThisButton property to True.
 
 Run the project. Click on the "?" button in the title bar, and then
   click on any control in the UserControl. The appropriate help is shown.
  
 NOTE: When you click on the "?" button and then click on the UserControl
   in the area not covered by contained controls, no help is shown. This is
   because the UserControl does not have a WhatsThisHelpId in design-mode.
   However, WhatsThisHelpId property is available when it is sited, and the
   client form can assign a value to it. If you want to assign a
   WhatThisHelpId at design-time itself, cover the UserControl with a Frame
   or PictureBox and assign the WhatsThisHelpId to that control.
 
 Stop the project. Go to Project Properties of Project2 and specify a
   helpfile for it.
 
 Set the WhatsThisHelpId of UserControl1 to a valid value. Add necessary
   controls and set their WhatsThisHelpId.
 
 Run the project. Click on "?," and then click on the UserControl in the
   area not covered by contained controls. Note that the correct Help is
   shown. Note that the help information shown comes from Project2's
   helpfile and not from UserControl1's helpfile. If this behavior is not
   desired, apply the "Note" from step 7.
 
 Method 2: Inheriting Help from the Client ApplicationIn some cases, such as when the UserControl is simple, it may not have its
own help file. In this case it is desirable to inherit the help system
provided by the client application.
 Step-by-Step ExampleStart a new ActiveX Control project. UserControl1 is created by default.
 
 Place three controls onto the UserControl.
 
 Select Add Project from the Project menu to add a new Standard EXE
   project. Project2 is created by default.
 
 Place UserControl1 onto Form1. Change the BorderStyle property of Form1
   to Fixed Single. Set the WhatsThisButton property to True.
 
 Select Project2 Properties from the Project menu. On the General tab,
   specify the help file in the Help File Name field.
 
 Set the WhatsThisHelpId of UserControl11 to a valid value. Add necessary
   controls to Form1 and set their WhatsThisHelpId.
 
 Run Project2. Click on "?" and click on UserControl11 in the area not
   covered by contained controls. The specified help topic is displayed. If
   any contained control is clicked, no help topic will be displayed. To
   achieve this effect implement the following steps:
  
 
 In the General Declarations section of UserControl1, add the
      following code:
     
         Public Property Get HelpFile() As String
           HelpFile = App.HelpFile
         End Property
         Public Property Let HelpFile(ByVal vNewValue As String)
           If Dir(vNewValue) = "" Then
               Err.Raise 53  ' File not found
           Else
               App.HelpFile = vNewValue
           End If
         End Property
         Public Sub InheritHelp(Optional nWhatsThisHelpId As Integer)
           Dim cTemp As Control
           If nWhatsThisHelpId = 0 Then
               nWhatsThisHelpId = UserControl.Extender.WhatsThisHelpID
           End If
           For Each cTemp In Controls
               On Error Resume Next  ' Ignore errors in next statement
               cTemp.WhatsThisHelpID = nWhatsThisHelpId  ' some controls
                                ' may not have WhatsThisHelpid property
               On Error GoTo 0  ' Turn off error handling
           Next
         End Sub
    
 
 In the client Form's General Declaration section, add the following
      code:
     
         Private Sub Form_Load()
           UserControl11.HelpFile = App.HelpFile
           UserControl11.InheritHelp  ' Pass WhatsThisHelpId if different
                 ' help Id is desired for contained controls
                 ' By default, the HelpId of usercontrol will be inherited
         End Sub
    
 
 
 Run the project. Click on "?" and click anywhere on the UserControl.
   Note that the specified Help Topic is displayed.
 
 
 REFERENCES
For additional information, please see the following articles in the
Microsoft Knowledge Base:
 Q142249
   : HOWTO: Implement "What's This?" Help in Visual Basic
  
 Q180733
   : HOWTO: Add Context-Sensitive Help to Your ActiveX Control
 
 Q173638
   : BUG: "What's This?" Button Disappears from MDI Child Forms
 Additional query words: 
kbDSupport kbDSD WhatsThisHelp kbVBp kbVBp400 kbVBp500 kbVBp600 kbCtrl kbActiveX
 
Keywords          : kbGrpVB Version           : WINDOWS:4.0,5.0,6.0
 Platform          : WINDOWS
 Issue type        : kbhowto
 |