Home > Archive > Visual Basic > February 2005 > Control array when dynamicly creating controls
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Control array when dynamicly creating controls
|
|
|
| Im trying to dynamicly create a control array. But i seem to be having
difficaulty doing this. I thought i could this by passing a value to .index
of the componets but it doesnt seem to work. The code im using
Set FrameTheatre = Controls.Add("vb.frame", "FrameTheatre")
With FrameTheatre
.Top = 200
.Left = 200
.Index = 0
Set .Container = FrameMain
.Height = 500
.Width = 4000
.Visible = True
.Caption = "Number 0"
.BorderStyle = 1
.ZOrder 0
End With
Set FrameTheatre = Controls.Add("vb.frame", "FrameTheatre")
With FrameTheatre
.Top = 4400
.Left = 200
.Index = 1
Set .Container = FrameMain
.Height = 500
.Width = 4000
.Visible = True
.Caption = "Number 1"
.BorderStyle = 1
.ZOrder 0
End With
How do i go about setting index's for dynamicly created controls?
Thanks
Jamie
| |
| Bob Butler 2005-02-26, 3:55 pm |
| "Jamie" <jammie@pc-forums.net> wrote in message
news:uAaiFLBHFHA.2744@tk2msftngp13.phx.gbl
> Im trying to dynamicly create a control array.
That isn't supported. Control arrays can only be created at design time.
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
| |
|
| ok, damn! but ok
"Bob Butler" <tiredofit@nospam.com> wrote in message
news:Ouq6WlBHFHA.1392@TK2MSFTNGP10.phx.gbl...
> "Jamie" <jammie@pc-forums.net> wrote in message
> news:uAaiFLBHFHA.2744@tk2msftngp13.phx.gbl
>
> That isn't supported. Control arrays can only be created at design time.
>
> --
> Reply to the group so all can participate
> VB.Net: "Fool me once..."
>
| |
| Rick Rothstein 2005-02-26, 3:55 pm |
| > >> Im trying to dynamicly create a control array.[color=darkred]
time.
You can, however, add one control (of the type you want the control
array to contain) to your form and set its Index property to 0. That
will create the control array so that you can then use the Load method
to create more members of the control array. Here is a simple example to
show how this works. Add a Shape control to your form, set its BackStyle
property to 1-Opaque and its Index property to 0. Then paste the
following code into the form's code window and run the project.
Rick - MVP
Private Sub Form_Load()
Dim X As Integer
SetProperties Shape1(0), 0, 500, 500, _
1000, 500, 4, vbGreen, vbRed
For X = 1 To 3
Load Shape1(X)
SetProperties Shape1(X), X, 500 + 1500 * X, 500, 1000, _
500, X + 1, QBColor(X), QBColor(7 - X)
Next
Me.Height = 2000
Me.Width = Shape1(3).Left + Shape1(3).Width + 500
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim X As Integer
For X = 1 To Shape1.UBound
Unload Shape1(X)
Next
End Sub
Private Sub SetProperties(Cntrl As Control, pShape As Integer, _
pLeft As Integer, pTop As Long, pWidth As Long, _
pHeight As Long, pBorderWidth As Integer, _
pBackColor As Long, pBorderColor As Long)
With Cntrl
.Visible = True
.Shape = pShape
.Move pLeft, pTop, pWidth, pHeight
.BorderWidth = pBorderWidth
.BackColor = pBackColor
.BorderColor = pBorderColor
End With
End Sub
| |
| Bob Butler 2005-02-27, 3:55 am |
| "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:%23Ks93sCHFHA.588@TK2MSFTNGP15.phx.gbl
>
> You can, however, add one control (of the type you want the control
> array to contain) to your form and set its Index property
Isn't that what I said... <g>
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
| |
| Rick Rothstein 2005-02-27, 3:55 am |
| > >>>> Im trying to dynamicly create a control array.
design[color=darkred]
>
> Isn't that what I said... <g>
Not exactly.<g> It is possible to get the idea that your message is
saying all members of the control array need to be created and indexed
at design time; I wanted to make clear that only one control array
member had to be created at design time and that additional members can
be dynamically added at run-time.
Rick
|
|
|
|
|