|
-
May 26th, 2005, 08:16 PM
#1
Thread Starter
Junior Member
How do you create an image box with code?
Hello, I'm new to these forums. My name is Josh, and my alias is obviously "The Pinball Wizard", after the The Who song. Anyway, I was wondering if there was a way to create an image box and place it somewhere with code. Kind of like the "ctrl-D" duplicate function of most windows programs. Also, since this is the first year I've been taking VB, and my teacher doesn't know a lot of the more advanced things, please elaborate on some of the more advanced code (if there is any), thanks.
-
May 26th, 2005, 08:24 PM
#2
Re: How do you create an image box with code?
Welcome to VBF, Josh!
Place command button onto your form and try to replcate this sample:
VB Code:
Private Sub Command1_Click()
Dim img As Control
Set img = Controls.Add("VB.Image", "imgTemp")
img.Move 300, 300
img.Picture = LoadPicture("c:\temp\some_image.bmp")
img.Visible = True
End Sub
As per advanced coding technics - I would suggest to take one step at the time - it'll come to you when you're ready for it.
-
May 26th, 2005, 08:24 PM
#3
Re: How do you create an image box with code?
Using Control Arrays. You can do it with any control. Set it's index property to zero (0) at design time.
then at runtime do something like this:
VB Code:
Load imgImage(1)
imgImage(1).Visible = True
imgImage(1).Left = 100
imgImage(1).Top = 100
-
May 26th, 2005, 08:30 PM
#4
Thread Starter
Junior Member
Re: How do you create an image box with code?
I understand (for the most part) both of those messages, thanks a lot! I have a few questsions for RhinoBull though.
What is "Control"?
What is the .Add function?
What is the .Move function?
-
May 26th, 2005, 08:40 PM
#5
Re: How do you create an image box with code?
1.
Every button, textbox, label, picturebox and others are CONTROLS.
Also every control is an object, so Dim img As Control is a declaration of an object variable of a Control type.
2.
Add is method of Controls collection that allows adding new instance of some control at run time.
3.
Move is method of a specified control that positions ("moves") object to a specified location: in my sample img.Move 300, 300 is the sample as img.Left = 300 and img.Top = 300
-
May 26th, 2005, 08:53 PM
#6
Thread Starter
Junior Member
Re: How do you create an image box with code?
Thanks for all those explanations, I'll keep those in mind. Your code didn't work, though. It came up with an error saying "Object Required", then it pointed to the line:
set img = control.add ("VB_image", "img_temp")
-
May 26th, 2005, 09:01 PM
#7
Re: How do you create an image box with code?
What you have IS NOT what I gave you, so take a look one more time and try to replicate it.
-
May 26th, 2005, 09:08 PM
#8
Thread Starter
Junior Member
Re: How do you create an image box with code?
Oh, sorry about that, it works now. Thanks a lot! I need this code for my end of the year school project, so you really helped.
-
May 26th, 2005, 09:09 PM
#9
Re: How do you create an image box with code?
That sounds better.
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
|