|
-
Nov 22nd, 2000, 01:20 PM
#1
Thread Starter
Addicted Member
Hi, im having a little trouble with this.
Code:
Option Compare Text
Option Explicit
Public WithEvents Boton As CommandButton 'Crea Botones para colocarse en frmDropWindow
Public WithEvents bLabel As Label 'Crea los Labels
Public WithEvents bFrame As Frame 'Crea los frames
Public globalX As Integer 'Equivale a la posicion X del raton en la pantalla
Public globalY As Integer 'Equivale a la posision Y del raton en la pantalla
Public ControlName As String 'Le coloca un nombre al nuevo control
Public ControlCaption As String 'Le cambia el Caption al nuevo control
Public Opciones As Integer 'Para conocer cual boton se presiono para crear el control
Public strTemp As String 'String a convertirse en instruccion
Public bIndex As Integer 'Index para poder crar mas instancias de Boton
'Funcion para convertir un string en un comando.
Private Declare Function EbExecuteLine Lib "vba6.dll" _
(ByVal pStringToExec As Long, ByVal Foo1 As Long, _
ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
Private Sub CrearFrame_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
CrearFrame.Drag vbBeginDrag
globalX = X
globalY = Y
Opciones = 3
End Sub
Private Sub CrearLabel_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
CrearLabel.Drag vbBeginDrag
globalX = X
globalY = Y
Opciones = 2
End Sub
Private Sub CrearBoton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
CrearBoton.Drag vbBeginDrag
globalX = X
globalY = Y
Opciones = 1
End Sub
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
CrearBoton.Move X - globalX, Y - globalY
CrearLabel.Move X - globalX, Y - globalY
CrearFrame.Move X - globalX, Y - globalY
End Sub
Public Sub Creacion(Source As Control, X As Single, Y As Single)
'Funcion para crear los controles en la forma frmDropWindow
If Opciones = 1 Then
bIndex = bIndex + 1
'ControlName = InputBox("Entra el nombre del control, es una variable, debe ser un nombre unico, que no comienze con numeros y que no tenga espacios!!!.", "Control Name")
Set Boton = frmDropWindow.Controls.Add("VB.CommandButton", Boton(bIndex))
Boton.Visible = True
Boton.Caption = InputBox("Entra el caption para el boton.", "Caption")
Boton.Move X - globalX, Y - globalY
Else
If Opciones = 2 Then
ControlName = InputBox("Entra el nombre del control, es una variable, debe ser un nombre unico, que no comienze con numeros y que no tenga espacios!!!.", "Control Name")
Set bLabel = frmDropWindow.Controls.Add("VB.Label", ControlName)
bLabel.Visible = True
bLabel.Caption = InputBox("Entra el caption para el boton.", "Caption")
bLabel.Move X - globalX, Y - globalY
Else
If Opciones = 3 Then
ControlName = InputBox("Entra el nombre del control, es una variable, debe ser un nombre unico, que no comienze con numeros y que no tenga espacios!!!.", "Control Name")
Set bFrame = frmDropWindow.Controls.Add("VB.Frame", ControlName)
bFrame.Visible = True
bFrame.Caption = InputBox("Entra el caption para el boton.", "Caption")
bFrame.Move X - globalX, Y - globalY
End If 'Opcion 1
End If 'Opcion 2
End If 'Opcion 2
End Sub
Private Sub Form_Load()
frmDropWindow.Show
bIndex = 0
End Sub
Function FExecuteCode(stCode As String, _
Optional fCheckOnly As Boolean) As Boolean
'Aqui se convierte el string en una instruccion.
FExecuteCode = EbExecuteLine(StrPtr(stCode), 0&, 0&, Abs(fCheckOnly)) = 0
End Function
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
frmToolBox.Creacion Source, X, Y
End Sub
The problem is that if i create a sub to add funcioality to Boton it will onli work with a new instance of it, if i create another, the old instace wont work again, is there away around that?
Thanks in advance!!
-
Nov 22nd, 2000, 01:34 PM
#2
Well ...
You could use something like this:
Code:
Dim WithEvents cmdButton As CommandButton
...
...
Private Sub cmdButton_Click()
...
...
End Sub
Private Sub Form_Load()
Set cmdButton = Command1
End Sub
Although for many buttons, this approach is dubious. You can use control arrays if you want a single procedure to handle all the actions/events of controls of a similar type.
-
Nov 22nd, 2000, 01:42 PM
#3
Thread Starter
Addicted Member
How can i make a control array?, sorry if im asking too much, im new at Vb .
Im trying to make an app that let me create a prototype program, so those instances needs to be created at runtime.
Thanks.
-
Nov 22nd, 2000, 01:58 PM
#4
Well ...
Let's say you want to create a control array of commandbuttons.
Place a commandbutton on your form. Set its name to whatever you like. This name will be the name of the control array.
Now copy the button image and paste it on the form again. There will appear a message box asking whether you want to create a control array. Click 'Yes' and you have another command button on the form. Check out its properties, they will be the same as the first one, only the 'Index' property will be different.
If you want this to happen through code, once you have one commandbutton on the form, set its index property to zero in design mode itself. This property is read-only at runtime.
Then in the code, use the Load method to add additional commandbuttons to the control array. For detailed help, check out the Load method in the MSDN help.
and come back to the forum if you have any problems. Nobody was ever at a loss by asking questions.
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
|