-
Final plea for help ;)
Okay now only respond if you KNOW how to do it or you're an experienced programmer and know it's not possible.
How do you create objects on a form during runtime???
-Justin
In a dungeon of Britannia a tamer says, "All Release".
-
<?>
I flunked sandbox and since I'm not a programmer I guess I'm ruled out.
:}
-
You can only do it if you have at least one of the control type already on the form, as an item in a control array. For example, put a Text Box onto a form, give it an index of 0. Then add this code:
Code:
Private Sub Form_Load()
Load Text1(1)
Text1(1).Visible = True
Text1(1).Top = Text1(1).Top + Text1(1).Height + 60
End Sub
If you want to create a control without one already present, you'd need to go the api route.
-
Sorry parksie but there's more than one way to do it.
Code:
Controls.Add "VB.Listbox", "MyListBox"
Me!MyListBox.Move 0, 0
Me!MyListBox.Visible = True
Me!MyListBox.AddItem "hi there"
-
If you have VB6 you can use the Controls.add method. You do not need to have a previous control of that type or control array.
To Create a label on a form:
Code:
Dim i As Object
Set i = Controls.Add("vb.label", "label1")
i.Visible = True
i.Caption = "hello"
-
Thx *Grins*
Yeah I'll try that...
I would be playing an online game right now but I'm on vacation using a slow *zz notebook (excuse Moi Francais).
Thx a lot 8].
-Justin
Newb - "Hey...I got the best connection. I just upgraded from a 28.8 to 56kbps"
Gimp - "Wazzup...I Just got a T1 for my Network. The cable was too slow :>"
-
you cannot manufacture controls just from nothing... i think... but since i'm not a top-class programmer, how should i know...
1. Place a label on the default form
2. Set the index to zero
3. paste this code where you want to create the object / control..
Load Label1(1)
Label1(1).Left = 1000
Label1(1).Top = 1000
Label1(1).Visible = True ' you need this. as default, its false
to get rid of it again...
unload label1(1)
-
What are you talking about? MartinLiss provided a way for creating controls from "nothing".
However, if you don't have VB6, you can still create them from scratch using the CreateWindowEx API.
Code:
Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle _
As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle _
As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight _
As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const WS_CHILD = &H40000000
Private Sub Form_Load()
retval = CreateWindowEx(0&, "Button", "Button1", WS_CHILD, 32, 32, 64, 64, Me.hwnd, 0, App.hInstance, ByVal 0&)
ShowWindow retval, 1
End Sub
-
If I am using VB5 is there a way to use something like controls.add w/o using the windows API?
-
Not really, which is probably why MS put it into VB6. Anyway, once you're used to it, using the API for things like this isn't that bad. Anyway, just use the "Load xx(1)" method, but have xx(0) as not visible on the form at startup. The end-user will never know the difference, and you won't really care.