|
-
Nov 17th, 2000, 11:30 PM
#1
Thread Starter
Addicted Member
Lets say that i make a program that creates lots of dynamic controls,(not really lots, but more like 5 or 6),using something like this...
'an if statement goes here
ControlName = InputBox("Give me the control name.", "Control Name")
Set Boton = frmDropWindow.Controls.Add("VB.CommandButton", ContolName)
Boton.Visible = True
Boton.Caption = InputBox("Give me the caption.", "Caption")
Boton.Move X - globalX, Y - globalY
Is there a way i can control every one of the new buttons?
maybe an array??
thanks for yout time!!
[Edited by nievesj on 11-17-2000 at 11:34 PM]
-
Nov 18th, 2000, 05:09 AM
#2
Addicted Member
If you are using VB 6 try this:
Code:
-------------------------------------------------
¡®The following code creates a commandbutton in runtime.
¡®If you like you can assign values from Textboxes to the properties.
¡®This cannot be applied to object arrays.
Option Explicit
Private WithEvents cmdMyButton as CommandButton
Private Sub Form_Load()
Set cmdMyButton = Controls.Add(¡°VB.CommandButton¡±,¡°Button¡±)
With cmdMyButton
.Visible = True
.Enabled = True
.Appearance = 1
.Width = 3000
.Height = 500
.Top = 600
.Left = 800
.Caption = ¡°Button Created in runtime¡±
End With
End Sub
Private Sub cmdMyButton_Click()
MsgBox ¡°Hi! Button has been created successfully.¡±
End Sub
-------------------------------------------------
If you are using VB 5 try this:
Code:
------------------------------------------------
¡®Draw a control (a CommandButton, for example) in advance (in design time).
¡®Set its Index as 0. Name it, say, cmdMyButton.
¡®The following code creates other 4 CommandButtons similar to cmdMyButton. ¡°700¡± is the vertical space between buttons.
'Again you can assign any values from your textboxes to the properties of the buttons
Dim i As Integer
For i = 1 To 4
Load CmdMyButton(i)
With CmdMyButton(i)
.Top = CmdMyButton(i - 1).Top + 700
.Left = CmdMyButton(i ¨C 1).Left
End With
Next
-------------------------------------------------
Hope it helps.
-
Nov 18th, 2000, 07:39 AM
#3
Hyperactive Member
doing it with arrays...
You need a seed control (not sure if that's true anymore in 6). Start with one textbox and set it's index to 0 (zero)
Then use the load method to create control number max(index) +1. The normal event handlers for controls will include the index of the paticular control.
eg. On Form1 there is a TextBox of index 0
Code:
Public Sub AddMore
Load TextBox1(1) '/ create a new text box with index 1
Load TextBox1(2) '/ create a new text box with index 2
End Sub
Then...
Code:
Private Sub TextBox1_Change(Index as Integer) '/ Notice the Index already automaticaly added to the definition. Applies for all control methods ( _Click etc)
MsgBox TextBox1(Index).Text
End Sub
Is this what your after?
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Nov 18th, 2000, 07:48 AM
#4
Addicted Member
Good. Tumblingdown's code is also true of my second code, like this:
Code:
------------------------------------
Private Sub cmdMyButton_Click(Index As Integer)
MsgBox "Hi. This is an Object Array."
End Sub
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
|