VB acts as a popular visual programming language, its powerful interface design function saves a lot of time for program designers. However, in the face of neatly arranged in a large amount of the same control, although it can be arranged during design, it is inevitable that it is accidentally moved in debugging, or later adds to some. So some people use statements to regulate in the program, and their hardships are imaginable (the author's deep experience), even if the position is ranked, its index attribute (.tabindex) is often chaotic. Can you Let the control of the control, index properties are automated? After some thinking, the author finally found a good solution and successfully applied to the registry modifier it developed. Example: New project, put a Frame control frame1, then add 4 check box in Frame1, pickBox2, checkbox3, checkbox4 add: ArrangeChildren frame1 running results for 4 check boxes The equal spacing is arranged in its container FRME1. In the design window, you can adjust their upper and lower positions, and will be neatly arranged in the upper and lower order in which they are designed, and their index sequence is arranged in a large arrangement. (Index order, do you know - let your program support keyboard operations). Dividing, you can increase anything in the container, reduce the number of controls (the type is the same), and they can be neatly arranged after running, so that one is eternal.
The following is the specific sub-process code public subrurse 'Father is the container control' function: (1) Sort the TabINDEX value of the sub-control within the container control 'Sort by: from top to bottom (.top) The value is made of small to large), TabINDEX is small to large '(2) any control of the sub-control in the container control DIM Children () AS Control' is the control in the container. The value of the array DIM tags () AS INTEGER 'Element Records the TabINDEX Value of the Control DIM TEMPCHILD AS Control' Temporary Controls DIM I AS Integer, J AS Integer Dim x AS Integer, Y AS Integer Dim Wchild As Integer, HChild AS Integer Dim Num AS INTEGER DIM STRTEMP AS STRING CONTEGER DIM STRTEMP AS STRING CONST Adjust As INTEGER = 150 'Try (Solt Address) Num = 0 for Each Child in Father.Parent.Controls' Search Each of the Controls in the Form in Container IF Typeof Child Is Checkbox Then' This judgment is to improve efficiency, do not care.container is Father Then Redim Preserve Children (Num) Redim Preserve Tags (NUM) Set Children (NUM) = Child Children (NUM) .tag = Num Tags (Num) = Children Num) .Tabindex Num = Num 1 end if Endiff Next if Num <1 THEN EXIT SUB 'When a child control in the container is not, quit Num = ubound (children)
SortProc tags' Press the array tags () to sort the controls from the small to large order, the smaller the control above the screen, the smaller the <.top> value, so it is also the <..tag> value. Children (i) .Tabindex = tags (children (i) .tag) Next I 'The control above the screen, the index value is small (the sort of the index value) ArrayTabINDEXPROC Children' x = 200 'controls in its container Start position wchild = 4000 'control width hchild = 255' control height y = (Father.Height - Adjust - (Num 1) * hchild) / (Num 2) for j = 0 To Num Children (j) .MOVE X, (J 1) * Y J * Hchild Adjust, WCHILD, HCHILD NEXT JEND SUBPUBLIC SUB SORTPROC (Arrint () AS Integer 'sorts the integer array DIM I AS INTEGER, J AS INTEGER DIM TEMP AS INTEGER DIM Num as integer 'array Num = ubound (arrit) for i = 0 to num for j = i 1 to Ubound (arrit) IF Arrint (i)> arrint (j) Temp = arrint (i) Arrint (i) = Arrint (j) arrint (j) = Temp end if Next J Next IEND SUB
Public SUB ARRAYTABINDEXPROC (ArrControl () AS Control) Sorts the array of controls 'control arrcontrol (0), ArrControl (1), ArrControl (2), ..... The TabINDEX value of ArrControl (n)' is low To high order, Dim i as integer, J AS Integer Dim Temp as control Dim num number for i = 0 to Num for j = i 1 to Ubound (ArrControl) IF ArrControl (i) .tabindex > ArrControl (j) .Tabindex THEN SET TEMP = ArrControl (i) Set ArrControl (i) = ArrControl (j) set arrcontrol (j) = Temp end if Next J Next IEND SUB