Hi
I know how to create a command button in runtime from an existing control
array of command buttons, that's not the issue here.
My poblem is the following: I have a Frame as part of a control array with a
command button on it, also part of a control array.
How do I create a new Frame + a new comand button, so the new button belongs
to the new frame ?
I need to create several frames having the same set of controls as part of
the frame, so when I move a frame all controls on it will follow it.
Thanks for all the help
Kjell
Norm Cook - 31 Aug 2004 13:39 GMT
Try this:
Option Explicit
Private WithEvents cmdObject As CommandButton
Private fraObject As Frame
Private Sub Form_Load()
'build the frame
Set fraObject = Form1.Controls.Add("VB.Frame", "fraOne")
With fraObject
.Visible = True
.Move 0, 0, Width \ 2, Height \ 2
End With
'build the button
Set cmdObject = Form1.Controls.Add("VB.CommandButton", "cmdOne")
With cmdObject
.Visible = True
.Caption = "My Button"
'put the button in the frame
Set .Container = fraObject
'center the button on the frame
.Move (fraObject.Width - .Width) \ 2, (fraObject.Height - .Height) \ 2
End With
End Sub
Private Sub cmdObject_Click()
MsgBox "This is a dynamically added control"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set cmdObject = Nothing
Set fraObject = Nothing
Set Form1 = Nothing
End Sub
> Hi
>
[quoted text clipped - 13 lines]
>
> Kjell
Gaurav - http://www.gauravcreations.com - 31 Aug 2004 13:41 GMT
you can do one thing...
after creating the control and form at runtime...drag and drop the control
on the frame programatically
check out the code here which will let you drag and drop controls on other
controls
http://www.freevbcode.com/ShowCode.asp?ID=1460
This might get very complicated....but this what i can think of as of now
--
Gaurav Creations
> Hi
>
[quoted text clipped - 13 lines]
>
> Kjell