|
-
January 14th, 1999, 12:35 AM
#1
Setting the TabIndex property of every control on a form
Hi
Here I am attaching the original code written by Timothy H. Fielder [[email protected]] and Edited by--Scott Lewis [[email protected]] for Setting tab index of different control in a form programmatically and also listing the problem I am facing :
I am getting problems with the code when the form has picture box. An error the property cannot be set is coming.
One more problem if the form has a frame with option buttons the focus is first going to the frame instead of the first control on the form say Text box.
The next problem I faced is if check boxes are placed in the frame then only the first check box is getting the focus. The other check boxes are being skipped and the focus is jumping to the next control outside the frame.
Can please check it out. If the code is corrected for the above then it will be really very useful for all of us.
Thanks & Regards
Sandeep
-----------------------------------------------------------------
Setting the TabIndex property of every control on a form
Written by Timothy H. Fielder [[email protected]] and
Edited by--Scott Lewis [[email protected]]
If you're like me, you hate having to go back and set the TabIndex
property on every control on a form every time the placement of controls
change. You can use the following subroutine to set the TabIndex property
of every control on a form from top to bottom, left to right. This comes
in especially handy on complex data entry forms with many labels, text
boxes, and command buttons.
Enter the following code in a form:
Private Sub Form_Load()
Call SetTabOrder(Me)
End Sub
Sub SetTabOrder(frm As Form)
Dim FormControl, CurrTop, CurrLeft, ctlControl
'-- Loop through all controls on the form
For ctlControl = 0 To frm.Count
CurrTop = 0 'set starting top
CurrLeft = 0 'set starting left
'-- Check every control on the form
For Each FormControl In frm.Controls
'-- Check if the control hasn't already been set
If FormControl.Tag True Then
'-- If current control's TOP property is greater than
'-- Start TOP, set new comparison value
If FormControl.Top > CurrTop Then
CurrTop = FormControl.Top
CurrLeft = FormControl.Left
'-- Control's top property is equal
ElseIf FormControl.Top = CurrTop Then
'-- If current control's LEFT property is greater than
'-- Start LEFT, set new comparison value
If FormControl.Left > CurrLeft Then
CurrTop = FormControl.Top
CurrLeft = FormControl.Left
End If
End If
End If
Next FormControl
'-- Check every control on the form if the top and left of
'-- the control match the top and left of largest control
For Each FormControl In frm.Controls
If FormControl.Top = CurrTop And _
FormControl.Left = CurrLeft Then
'-- set it's tabindex to 0 which will move all previously
'-- set tabindexes to 1 larger than they are now
FormControl.TabIndex = 0
'-- Do not process again
FormControl.Tag = True
End If
Next FormControl
Next
End Sub
From--Timothy H. Fielder [[email protected]]
Edited by--Scott Lewis [[email protected]]
Contributing Editor, Inside Visual Basic
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|