Results 1 to 5 of 5

Thread: How do I do a layout in Visual Basic 6?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    13

    Question How do I do a layout in Visual Basic 6?

    Hi,

    How do I layout of Buttons using either a do while loop or for loop.
    The layout must be in columns and rows like in grid of x by y.

    Hopefully the x and y or Rows and Columns can be declared in a text box.

    Thanks in Advance.

    Tom

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,794

    Re: How do I do a layout in Visual Basic 6?

    Make a control array.

    If you don't know how to make a control array, do this:
    Put a command button on the form, go to the properties, and change the Index to 0
    Then copy and paste this code:
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim K As Long
    3.    
    4.     For K = 1 To 10
    5.         Load Command1(K)
    6.        
    7.         Command1(K).Visible = True
    8.         Command1(K).Left = Command1(K - 1).Left
    9.         Command1(K).Top = Command1(K - 1).Top + Command1(K - 1).Height + 90
    10.     Next K
    11. End Sub
    And to make a grid:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim K As Long
    5.    
    6.     For K = 1 To 99
    7.         Load Command1(K)
    8.         Command1(K).Visible = True
    9.  
    10.         If (K Mod 10) = 0 Then
    11.             Command1(K).Left = Command1(K - 10).Left + Command1(K - 10).Width + 90
    12.             Command1(K).Top = Command1(0).Top
    13.         Else
    14.             Command1(K).Left = Command1(K - 1).Left
    15.             Command1(K).Top = Command1(K - 1).Top + Command1(K - 1).Height + 90
    16.         End If
    17.     Next K
    18. End Sub

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: How do I do a layout in Visual Basic 6?

    Here's a sample of mine (also using control array):
    NOTE: to run this sample you must create in design one textbox and set its Index = 0.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     CreateGrid 5, 7
    5. End Sub
    6.  
    7. Public Sub CreateGrid(x As Integer, y As Integer)
    8. Dim i%, j%
    9.  
    10.     For i = 1 To x * y - 1
    11.         Load Text1(i)
    12.         If i Mod x <> 0 Then
    13.             Text1(i).Move Text1(i - 1).Left + Text1(i).Width, Text1(i - 1).Top
    14.         Else
    15.             Text1(i).Move Text1(0).Left, Text1(i - 1).Top + Text1(i).Height
    16.         End If
    17.         Text1(i).Visible = True
    18.     Next i
    19.  
    20. End Sub

  4. #4
    Addicted Member
    Join Date
    Feb 2006
    Location
    The Sea of Tranquility
    Posts
    252

    Re: How do I do a layout in Visual Basic 6?

    Or just copy and paste a control and click yes on the do you want to create a control array message box

    Rich

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    13

    Re: How do I do a layout in Visual Basic 6?

    Thanks for your help.

    I was thinking I could have done by creating one button say called cmdButton with a index of 0 then doing a loop like this.

    For rows = 1 to 4
    For cols = 1 to 4
    With cmdButton(rows)
    .Left = cmdButton(rows * cols).Left = cmdButton(rows- 1).Left _
    + cmdButton(rows-1).width + 25).
    .Top = cmdButton(rows * cols).Top = cmdButton(cols -1).Top _
    + cmdButton(cols-1).height + 25)
    .width = 300
    .height = 300
    .Visible = True
    End With
    Next cols
    Next rows

    But im not sure if that would work!
    Thanks again
    Tom

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width