|
-
May 31st, 2005, 02:54 AM
#3
Re: [VB] How to load a controll at runtime.
Now for the last example you need to use the IDE a bit more. The simples way to accomplish this is to make a command button or what ever you want and drag it to the form like you normaly do. Change the name to what you want. Like I did: cmdButton. Then copy the command button and paste it to the form again. Then you will have a pop up message that asks you if you want to make a control array. Press yes. Then you have a control array called cmdButton of type command buttons. Now you can delete the second command buttons if you want. Becuase now we are going to load as many as we want using code. You do it like this:
VB Code:
Private Sub Form_Load()
Dim i As Integer
For i = 1 To 4
Load cmdButton(i)
With cmdButton(i)
.Left = 750 * i
.Top = 1000
.Width = 700
.Height = 500
.Caption = "Hello"
.Visible = True
End With
Next i
End Sub
And that is all you need. You don't have to make pointers, and you don't have to set any pointers to nothing. Pretty simple. Just remember that you have all ready loaded at least one object, so you can't load that one again. That is why my for loop goes from 1 and not 0. If I didn't delete the second command button that I made, then it had to go from 2 and so on. We are using the load function to load a new instance. Remember no paranteses around the object that you want to load. The rest of the code you have looked at all ready. This way you can make a lot of things easier. But remember that it takes a lot of CPU power to load the objects. So if you are making a progress bar or anything this way and you are loading the object while you are showing the progress a lot of the CPU power will go to make the objects. So it can be a better to make the objects earlier in the app, and then show them when you need it. But you will probably find out what is best for you when you are making the app. If you have questions about this tutorial please post a question in the forum, where there is probably more then just me that can answer.
ØØ
Last edited by NoteMe; May 31st, 2005 at 03:06 AM.
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
|