VBGood网站全文搜索 Google

首页 - 经验之谈 - Work around the Tabbed Dialog control tab glitch
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:8264, 日期:2001-07-18
Work around the Tabbed Dialog control tab glitch

While not perfect, the Tabbed Dialog control (also known as the
SSTab) provides a much needed improvement over the older Tab Strip
control. If you注释:re not familiar with this control, unlike it注释:s
predecessor, the Tabbed Dialog contains pages upon which you can
place controls. These pages act as containers and automatically
hide their subordinate controls when you click a new tab. For the
most part, the control works without a hitch.

However, if you add an OCX control, such as a Masked Edit or Rich
Textbox, to a page, the Tabbed Dialog may exhibit some strange
behavior. Normally at runtime, when you press the [Tab] key, Visual
Basic tabs between only those subordinate controls on the visible
page. If the Tabbed Dialog contains an OCX control, though, it
will include this control in the tab order, regardless of whether
or not the page hosting the control is visible. Fortunately, there注释:s
an easy fix.

Apparently, when a control isn注释:t visible in the Tabbed Dialog,
it注释:s because VB has moved it far off to the left of the Tabbed
Dialog注释:s left edge. When you select a tab, VB moves the appropriate
controls back into Tabbed Dialog注释:s main area. As a result, we can
use this behavior to our advantage by testing a control注释:s Left
property. If it注释:s greater than zero (visible) then we want VB to
tab to it. Otherwise, we want to set the control注释:s TabStop property
to false.

The following procedure shows an example of this fix:

Private Sub PreventTab()
Dim ctl As Control
For Each ctl In Me.Controls
With ctl
If TypeOf .Container Is SSTab Then
注释:Not all controls have the TabStop property
On Error Resume Next
..TabStop = (.Left > 0)
On Error GoTo 0
End If
End With
Next ctl
End Sub

As you can see, this procedure loops through all the controls on
the form, testing for those contained in the SSTab (Tabbed Dialog)
control. It then sets each control注释:s TabStop property equal to
the Boolean result of the expession

..Left > 0

Controls in the visible portion of the SSTab will evaluate to True,
while those off the form won注释:t.