[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)
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.
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
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
Re: [2005] Random Buttons Problem
Quote:
Originally Posted by jmcilhinney
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.
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.
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.
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=