|
-
Nov 21st, 2000, 03:36 PM
#1
Thread Starter
New Member
Hi,
I am building form with dynamic insert of controls (such as Frame and Labels).
I've tried to put Frame on the Form, another Frame on the Frame, and afterwards a Label on the last Frame by using the Controls.Add method.
The problem is that the Label disappear to the back of the Frame.
Using the ZOrder method wouldn't help.
Hoe can it be done?
-
Nov 21st, 2000, 03:49 PM
#2
Labels belong to a different layer, therefor they cannot be higher than a Frame, Button, PictureBox and other graphical controls.
As a solution, you can place the Label inside the Frame.
Code:
Label1.Container = Frame1
Label1.Move 0, 0
-
Nov 22nd, 2000, 01:36 PM
#3
Thread Starter
New Member
Thanks.
The problem still remain.
I'm using this code in a function, that running each time I wish to insert a new control. The MainFrame is the first control that I'm inserting and it the container of the following label controls that I want to add but when it get to the 'Else' it giving me the error:"Invalid object use".
What can I do to solve it?
Dim MyControl As Control
Set MyControl = Form.Controls.Add(ControlType, ControlName, Form)
Static y As Control
If MyControl.Name = "MainFrame" Then
Set y = MyControl
Else
Set MyControl.Container = y
End If
-
Nov 22nd, 2000, 01:52 PM
#4
Well ...
Maybe the 'Static' word?
Just a wild guess, curse me if I am wrong.
-
Nov 23rd, 2000, 06:25 AM
#5
Thread Starter
New Member
You were half right - but don't worry, you weren't half cursed.
The word 'static' wasn't really necessary so I dropped it and use 'Dim' instead, but it didn't solve the problem.
When I'm using debug I can see that after inserting new control in the name of MyControl (of type such as Label) to the Form while the Frame 'MainFrame inserted before , the situation is like that:
'MyControl.Container' is of type Variant/Object/Form1 while
'y' is of type Control/Frame
Maybe this will explain the problem and you'll be able to help me.
-
Nov 23rd, 2000, 08:59 AM
#6
Fanatic Member
I found a thread earlier in the week about dynamically creating controls. I can't find it again but kept the code and have modified it, the following code will create a label on the frame control. I am probably telling you what you already know but this seemed to work well for me.
Code:
Private WithEvents btnObj As Label
Private Sub Command1_Click()
Set btnObj = Controls.Add("VB.Label", "btnObj")
Set btnObj.Container = Frame1
With btnObj
.Visible = True
.Width = 2000
.Caption = "Hello"
.Top = 1000
.Left = 1000
.BackColor = vbRed
.ForeColor = vbWhite
.FontBold = True
.FontSize = 14
End With
End Sub
Because Frame1 is an object you do have to use the set command as you have done. I think a part of the problem is you are using FORM as the third parameter of the Add method for the controls collection of the form. I however do not specify a third parameter.
I also use the withevents keyword to allow me access to the events of the dynamiclly created control.
Let me know if any of this helps.
-
Nov 24th, 2000, 07:25 AM
#7
New Member
label
I encountered the label problem you mentioned, I fixed it by using a textbox instead. It works equally well. Just need to remember to set a size for the text box so that the text can fit inside it. Hope this helps.
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
|