|
-
Mar 3rd, 2001, 12:24 PM
#1
Thread Starter
Fanatic Member
I have 15 command buttons I want to be positioned upon form load.
I can do this the 'long' way by doing this:
command1.top=100
command1.left=200
ect..for all 15. but i know I can put them into a collection or something and just loop through all buttons.
what i need is for 3 buttons to be next to each other then the next three to be just below the first three then the next three to be just below the second three(like the buttons on your number pad or phone.
I don't know exactly how to write the code to do this though(with a collection or for next loop or something)
thanks
-
Mar 3rd, 2001, 01:13 PM
#2
Lively Member
Try this...
first put all the buttons into a control array ranging from 0 to 14 then put this in the form_load event...
Dim x As Integer
Dim y As Integer
Dim num As Integer
Const inc As Integer = 500
x = inc
y = inc
Do While num < 15
Command1(num).Height = y
Command1(num).Width = x
num = num + 1
Loop
num = 0
Do While y <= (inc * 5)
Do While x <= (inc * 3)
Command1(num).Top = y
Command1(num).Left = x
x = x + inc
num = num + 1
Loop
x = inc
y = y + inc
Loop
Hope this is what your looking for!
"Programmers by passion, profession and insanity.
Insane from the irrational, illogical and VB."- ThreeMinds
-
Mar 3rd, 2001, 02:30 PM
#3
Addicted Member
ok make a command button
set index to command1 to 0
then put this code in form_load
Dim I As Integer, I2 As Integer, I3 As Integer
I2 = 0
For I = 1 To 14
I2 = I2 + 1
Load Command1(I)
Command1(I).Top = Command1(I - 1).Top
If I2 = 3 Then
Command1(I).Top = Command1(I - 1).Top + Command1(I - 1).Height
I3 = Command1(0).Left
I2 = 0
Else
I3 = Command1(I - 1).Left + Command1(I - 1).Width
End If
Command1(I).Left = I3
Command1(I).Visible = True
Next I
Thanks For All Your Help!
If I helped you I give God the glory
From CodeGreen
-
Mar 3rd, 2001, 02:34 PM
#4
Thread Starter
Fanatic Member
cool
thanks to both of you
-
Mar 3rd, 2001, 02:49 PM
#5
Thread Starter
Fanatic Member
how do I make each button have it's own sub?
I mean, I want to be able to click any button and get a msgbox that tells me the number of the button.
thanks again
-
Mar 3rd, 2001, 02:51 PM
#6
Thread Starter
Fanatic Member
-
Mar 3rd, 2001, 03:53 PM
#7
Thread Starter
Fanatic Member
one more thing.
I actually need the buttons to be four accross.
I got this to work with your code codegreen.
but when I try and change the captions to read,starting from the upper left,
1,2,3,4 ect...the first button says 14 and then the next button says 1, 2 follows ect... then the last button (lower right) says 14 again.
how do I fix this?
if I didn't explain myself well enough let me know, I try and make it clearer.
thanks again
-
Mar 3rd, 2001, 04:07 PM
#8
Addicted Member
Dim I As Integer, I2 As Integer, I3 As Integer
I2 = 0
Command1(0).Caption = 0 ' or Command1(0).Caption = 1
For I = 1 To 14
I2 = I2 + 1
Load Command1(I)
Command1(I).Top = Command1(I - 1).Top
If I2 = 4 Then
Command1(I).Top = Command1(I - 1).Top + Command1(I - 1).Height
I3 = Command1(0).Left
I2 = 0
Else
I3 = Command1(I - 1).Left + Command1(I - 1).Width
End If
Command1(I).Left = I3
Command1(I).Visible = True
Command1(I).Caption = I
Next I
'''''''''
if you need the first one to be 1 not 0 then Command1(I).Caption = I + 1
Last edited by codegreen; Mar 3rd, 2001 at 04:13 PM.
Thanks For All Your Help!
If I helped you I give God the glory
From CodeGreen
-
Mar 3rd, 2001, 04:45 PM
#9
Lively Member
you can try this if you want to...
Just change the values in the do while loops to the hight and width that you want it (in this case 4x4) and add in the iff statement right after it to make sure that it doesn't go past the end of the array:
Do While y <= (inc * 4)
Do While x <= (inc * 4)
If num = 15 Then
Exit Sub
End If
you should end up with something like this:
****
****
****
***
* = command button
Hope this works
Owen.
"Programmers by passion, profession and insanity.
Insane from the irrational, illogical and VB."- ThreeMinds
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
|