如何在VB6运行时分配TabIndex
我正在开发 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设窗体上有 5 个控件,它们的 Tab 键顺序如下所示
如果将 3 更改为 1 那么
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
If you change 3 to 1 Then it will look like this
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).