James_stillman
asked on
Adding items to a frame on the fly
I want to add items to a frame in runtime.
During runtime I am going to create the labels and load them into a pre existing frame if I can. iS There a way that I can do this?
Can anyone help please? I'm sure it should be easy if you know how.
I have an API call setParent but cannot use it because the label control has no Hwnd property and this is required by the API call.
Cheers
James
During runtime I am going to create the labels and load them into a pre existing frame if I can. iS There a way that I can do this?
Can anyone help please? I'm sure it should be easy if you know how.
I have an API call setParent but cannot use it because the label control has no Hwnd property and this is required by the API call.
Cheers
James
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks
Just thought I'd add my $0.02....
I tried the code above for labels and for textboxes. The labels worked fine, but the textboxes caused big fat memory access errors. They were so bad that I ended up having to totally un-install and then re-install VB6!
Here's the VB6 code I ended up using...
Dim mytextbox() as textbox
ReDim Preserve mytextbox(0)
dim strTemp as String
dim xpos as Long
dim ypos as long
xpos = Frame1.Left + 700 ' change as needed
ypos = Frame1.Top + 700 'change as needed
For i = 0 to end
ReDim Preserve mytextbox(ubound (mytextbox) + 1)
strTemp = "TextBox" & i
Set mytextbox(i) = Controls.Add("VB.TextBox", strTemp)
With mytextbox(i)
Set .Container = Frame1
.Top = ypos
.Left = xpos
.Visible = true
End With
ypos = ypos + 700
Next
-------------------------- --------
So now you know. :)
I tried the code above for labels and for textboxes. The labels worked fine, but the textboxes caused big fat memory access errors. They were so bad that I ended up having to totally un-install and then re-install VB6!
Here's the VB6 code I ended up using...
Dim mytextbox() as textbox
ReDim Preserve mytextbox(0)
dim strTemp as String
dim xpos as Long
dim ypos as long
xpos = Frame1.Left + 700 ' change as needed
ypos = Frame1.Top + 700 'change as needed
For i = 0 to end
ReDim Preserve mytextbox(ubound (mytextbox) + 1)
strTemp = "TextBox" & i
Set mytextbox(i) = Controls.Add("VB.TextBox",
With mytextbox(i)
Set .Container = Frame1
.Top = ypos
.Left = xpos
.Visible = true
End With
ypos = ypos + 700
Next
--------------------------
So now you know. :)
Blimey, this question is so old I had forgotten I ever answered it.
I assume these errors happened when the form was unloaded?
I assume these errors happened when the form was unloaded?
Here's an example that works fine:
Put a text box on the form and give it index 0
Put a frame on the form
Put a button on the form
Each button click loads a new instance of the text box.
On the form_unload procedure the textboxes are unloaded carefully.
This code runs without problems on my PC - VB6+SP4
Option Explicit
Private Sub Command1_Click()
Load Text1(Text1.UBound + 1)
With Text1(Text1.UBound)
Set .Container = Frame1
.Top = Text1(0).Height * (Text1.UBound - 1)
.Visible = True
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Do While Text1.UBound > 0
Set Text1(Text1.UBound).Contai ner = Me
Unload Text1(Text1.UBound)
Loop
End Sub
Put a text box on the form and give it index 0
Put a frame on the form
Put a button on the form
Each button click loads a new instance of the text box.
On the form_unload procedure the textboxes are unloaded carefully.
This code runs without problems on my PC - VB6+SP4
Option Explicit
Private Sub Command1_Click()
Load Text1(Text1.UBound + 1)
With Text1(Text1.UBound)
Set .Container = Frame1
.Top = Text1(0).Height * (Text1.UBound - 1)
.Visible = True
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Do While Text1.UBound > 0
Set Text1(Text1.UBound).Contai
Unload Text1(Text1.UBound)
Loop
End Sub
ASKER
Cheers Caraf_g didn't really think about that one.