HOWTO: Fire TabStrip's Click Event When Using Msgbox in BeforeClick

ID: Q238312


The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0


SUMMARY

If a message box is displayed in a TabStrip control's BeforeClick event handler, the TabStrip control's Click event handler will not be fired, even if the Cancel parameter is set to False. In some situations it may be necessary to validate the information in the BeforeClick event handler and then display a message box to determine if the user wishes to continue. If so, the Click event should be fired.


MORE INFORMATION

The optimum workaround depends upon the situation:

Situation 1:

If you don't need to reference the TabStrip1.SelectedItem.Index property in the Click event handler, you can call the function directly. For example:

Private Sub TabStrip1_BeforeClick(Cancel As Integer)
   If MsgBox("Do you want to continue?", vbYesNo) = vbYes Then
      TabStrip1_Click
   Else
      Cancel = True
   End If
End Sub

Private Sub TabStrip1_Click()
    MsgBox "click event handler is called"
End Sub 

Situation 2:

If the Click event handler is called inside the BeforeClick event, the index value has not yet been changed. So if you must reference the TabStrip1.SelectedItem.Index property, you must call the Click event after exiting the BeforeClick event. One solution is to use a Timer control. For example:

Option Explicit

Private Sub Form_Load()
   TabStrip1.Tabs(1).Selected = True
   Timer1.Interval = 1
   Timer1.Enabled = False
End Sub

Private Sub TabStrip1_BeforeClick(Cancel As Integer)
   If MsgBox("Do you want to continue?", vbYesNo) = vbYes Then
      Timer1.Enabled = True 'call the click handler
   Else
      Cancel = True
   End If
End Sub

Private Sub TabStrip1_Click()
   msgbox "Change to tab " & TabStrip1.SelectedItem.Index
End Sub

Private Sub Timer1_Timer()
   Timer1.Enabled = False
   TabStrip1_Click 'call it here
End Sub 


REFERENCES

For more information regarding the TabStrip control, especially the BeforeClick and Click events, please see the MSDN Library.

Additional query words:

Keywords : kbActiveX kbActivexEvents kbTabCtrl kbVBp kbVBp500 kbVBp600 kbGrpVB kbDSupport
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: August 24, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.