Results 1 to 8 of 8

Thread: [2005] Random Buttons Problem

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2008
    Posts
    13

    [2005] Random Buttons Problem

    I have to design a program for my school where i have a set of 50 buttons that when i click a button go into a random order.

    My problem is, is when i click the button they all over lap each other.

    So i need help in finding a way to make it so they are all separated and not overlapping each other.

    Also is there away to use a button as a array like

    Button1.top = blah blah turn that into
    Button(i).top = blah blah
    (for a for i loop that is)

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Random Buttons Problem

    1. Use a TableLayoutPanel. It will only accept one control in each cell so they are all laid out in a table automatically.

    2. An array of Buttons, or any control for that matter, is created in code just like any other array. That said, can access controls in a TableLayoutPanel by column and row index, so that may be easier.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2008
    Posts
    13

    Re: [2005] Random Buttons Problem

    Quote Originally Posted by jmcilhinney
    1. Use a TableLayoutPanel. It will only accept one control in each cell so they are all laid out in a table automatically.
    Ok cheers for this i will check it out later

    Quote Originally Posted by jmcilhinney
    2. An array of Buttons, or any control for that matter, is created in code just like any other array. That said, can access controls in a TableLayoutPanel by column and row index, so that may be easier.
    So to make a button array without TableLayoutPanel i need certain code? What is this code?

    Thanks

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Random Buttons Problem

    Have you ever created an array of Strings or Integers or something like that? An array of Buttons is exactly the same.

    http://startvbdotnet.com/language/arrays.aspx
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2008
    Posts
    13

    Re: [2005] Random Buttons Problem

    Quote Originally Posted by jmcilhinney
    Have you ever created an array of Strings or Integers or something like that? An array of Buttons is exactly the same.

    http://startvbdotnet.com/language/arrays.aspx
    Well i have in visual basic six but not studio.

    Anyway heres the code i have (example)

    Dim i as Integer

    For i = 1 to 40
    button(i).top = 465
    button(i).left = 300
    Next

    But it gives me a error when i do this.

  6. #6
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: [2005] Random Buttons Problem

    Quote Originally Posted by Shadow-Walker
    Well i have in visual basic six but not studio.

    Anyway heres the code i have (example)

    Dim i as Integer

    For i = 1 to 40
    button(i).top = 465
    button(i).left = 300
    Next

    But it gives me a error when i do this.
    This is because there are no control arrays in .net.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Random Buttons Problem

    Control arrays as they existed in VB6, i.e. created in the designer, are not supported in VB.NET. As i have already said, an array of controls can be created in code just like any other array. Did you follow the link I provided? If so then you know how to create an array in code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: [2005] Random Buttons Problem

    A similar thing that you are trying to do can be done like this.

    Code:
     Dim g As New Button
            Dim hs As New Button
            g.Name = "pro"
            hs.Name = "ko"
            Dim go As New List(Of Button)
            go.Add(g)
            go.Add(hs)
    
            go.Item(1).Top=
            go.Item(1).Left=

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