|
-
Dec 7th, 2001, 12:09 PM
#1
Thread Starter
Frenzied Member
creating picture box controls at run-time
Please could you tell me how to create a picture box at run-time. What i want to do is right click on the form, and have a pop menu come up. From the menu click create a picture control to be added to form. Can you create controls like this at run-time
Many thanks in advance
-
Dec 7th, 2001, 12:54 PM
#2
You sure can! It goes something like this.
VB Code:
Option Explicit
Dim WithEvents picNew As PictureBox
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
Me.PopupMenu mnuPop
End If
End Sub
Private Sub mnuPopCreate_Click()
Set picNew = Controls.Add("vb.Picturebox", "picNew")
With picNew
.Left = 400
.Top = 600
.Visible = True
.BackColor = vbRed
End With
End Sub
-
Dec 7th, 2001, 02:33 PM
#3
Addicted Member
I could be mistaken, but that would only allow you to add one more PictureBox, then you would get an error saying that a control with the name "picNew" already exists...
I've been adding them this way.... Then I can add as many as I needed to.....
Code:
Private Sub Command1_Click()
Dim X As Integer
X = picNew.Count
Load picNew(X)
With picNew(X)
.Left = X * 100
.Top = X * 100
.Visible = True
End With
End Sub
The only problem I've had with this is that you already have to have one PictureBox on your form at DesignTime with the "Index" property set to "0"....
"Don't take life too seriously, you'll never get out alive"
from Van Wilder
-
Dec 7th, 2001, 02:44 PM
#4
Frenzied Member
CadDragon:
me too i like it better this way,
that way if you want to put code for onClick or something you can
and control it with the index!!
-
Dec 7th, 2001, 03:09 PM
#5
Addicted Member
Yeah, you could do something cool like have a button on a form that says "Do you like buttons?" and when they click "Yes", it it fills the users screen with buttons and have it where each button is unloaded when it's clicked according to its index, so that they have to clear out a whole lotta buttons to get back to the main form so they can close the program..... Hehe, just an idea....
"Don't take life too seriously, you'll never get out alive"
from Van Wilder
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
|