|
-
Aug 28th, 2000, 03:10 PM
#1
Thread Starter
Lively Member
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".
-
Aug 28th, 2000, 03:16 PM
#2
_______
<?>
I flunked sandbox and since I'm not a programmer I guess I'm ruled out.
:}
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 28th, 2000, 03:24 PM
#3
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 28th, 2000, 03:47 PM
#4
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"
-
Aug 28th, 2000, 03:49 PM
#5
Lively Member
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"
-
Aug 28th, 2000, 04:02 PM
#6
Thread Starter
Lively Member
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 :>"
-
Aug 29th, 2000, 05:44 AM
#7
New Member
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)
-
Aug 29th, 2000, 08:16 AM
#8
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
-
Aug 29th, 2000, 09:39 AM
#9
Addicted Member
If I am using VB5 is there a way to use something like controls.add w/o using the windows API?
-
Aug 29th, 2000, 12:16 PM
#10
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
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
|