如何在VB6运行时分配TabIndex

发布于 2024-10-22 04:09:31 字数 849 浏览 0 评论 0原文

我正在开发 VB6 维护应用程序。它是一个基于 Windows 的应用程序。我的客户想要在运行时配置控件选项卡索引。我正在将客户端设置保存到访问数据库。

以下子集控件的选项卡索引

Private Sub SetTabSetting()
Dim i As Integer
Dim Ctr As Control
If UBound(TSetting) > 0 Then
    For i = 0 To UBound(TSetting)
        For Each Ctr In Me.Controls
            Dim matched As Boolean: matched = False

            If Ctr.Name = TSetting(i).ControlName Then
               Ctr.TabIndex = TSetting(i).TabIndexNum
               Exit For
            End If
        Next
    Next
End If
End Sub

TSetting是全局模块中定义的类型数组。

Private Sub Form_Load()
  GetRATabSetting
  SetRATabSetting
End Sub

GetRATabSetting 正在从数据库中提取值并将其填充到 TYPE 数组中。

代码执行得很好。甚至值也从数据库中提取并正确设置到控件中。但该选项卡遵循设计时设置的索引。

我做错了吗?是否可以在运行时设置控件的 tabindex ?还有其他方法可以执行此操作吗?

I am working in a VB6 maintenance application. It is a windows based application. My client wants to configure the controls tab index at runtime. I am saving the client setting to the access database.

The following sub sets the tab index of the controls

Private Sub SetTabSetting()
Dim i As Integer
Dim Ctr As Control
If UBound(TSetting) > 0 Then
    For i = 0 To UBound(TSetting)
        For Each Ctr In Me.Controls
            Dim matched As Boolean: matched = False

            If Ctr.Name = TSetting(i).ControlName Then
               Ctr.TabIndex = TSetting(i).TabIndexNum
               Exit For
            End If
        Next
    Next
End If
End Sub

TSetting is a TYPE Array defined in a Global Module.

Private Sub Form_Load()
  GetRATabSetting
  SetRATabSetting
End Sub

GetRATabSetting is extracting the values from the database and populating into the TYPE arrray.

The code is getting executed quite fine. Even the values get extracted from the database and set to the controls correctly. But the tab is following the index what is set in the designtime.

Am I doing any mistake? Is it possible to set the tabindex of the controls at runtime ? Is there any other way to perform this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独自唱情﹋歌 2024-10-29 04:09:31

假设窗体上有 5 个控件,它们的 Tab 键顺序如下所示

Index - TabIndex
1 - 0
2 - 1
3 - 2
4 - 3
5 - 4

如果将 3 更改为 1 那么

Index - TabIndex
1 - 0
2 - 2
3 - 1
4 - 3
5 - 4

Visual Basic 将自动将所有 tabindex 增加 1,所有 tabindex 等于或高于您指定的 tabindex。永远不会有两个控件具有相同的 tabindex 的情况。这会给像您这样分配选项卡索引的例程带来问题。

您应该做的不是直接从数据库分配 tabindex,而是构建与选项卡索引关联的控制索引数组。根据 tabindex 对它进行排序,然后开始分配,从 tabindex 0(或最低)开始。

Suppose you have 5 controls on a form and their tab order is like this

Index - TabIndex
1 - 0
2 - 1
3 - 2
4 - 3
5 - 4

If you change 3 to 1 Then it will look like this

Index - TabIndex
1 - 0
2 - 2
3 - 1
4 - 3
5 - 4

Visual Basic will automatically bump up by one all tabindex equal to and higher than the one you assigned. There will never be a time where two controls have the same tabindex. This causes problems for routines that assign tab indexes like yours.

What you should do is not assign the tabindex directly from the database but rather build an array of control indexes associated with tab indexes. Sort it based on the tabindex and then start assigning, starting at whatever is at tabindex 0 (or the lowest).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文