|
-
Dec 18th, 2005, 12:15 PM
#1
Thread Starter
Hyperactive Member
creating new Image object
i am building a word processor and want to be able add picture to the form. how could i add create imageboxes at runtime so that the user can add pictures as many times as they like. any help would be great as i'm completely baffled how to do this. sorry i dont have any code to post to show.
-
Dec 18th, 2005, 12:25 PM
#2
Re: creating new Image object
There two (and ony two) ways to add control at runtime:
- control array (easy and most commonly used)
- controls collection (also easy but creates some problems accessing new controls)
In any case to use control array add new image control in design and set its Index = 0. At runtime use the following logic:
VB Code:
Load Image1(Image1.Ubound + 1)
Image1(Image1.Ubound).Move 100, 100 'you must determine where you want it
Image1(Image1.Ubound).Picture = LoadPicture("full_path_goes_here")
Image1(Image1.Ubound).Visible = True
To utilize controls collection here is the logic:
VB Code:
Dim img As Image
Set img = Controls.Add("VB.Image", "imgTemp") 'you need to come up with unique sequence to name each new control
img.Picture = LoadPicture("full_path_goes_here")
img.Move ...
img.Visible = True
-
Dec 22nd, 2005, 05:31 AM
#3
Thread Starter
Hyperactive Member
Re: creating new Image object
RhinoBull, with the control array code(which i can understand and easily use) does this load many pictures at once or only one and also can, if i put in a function say, run to add as many pictures as i want all individually. Thanks for the code already
-
Dec 22nd, 2005, 08:48 AM
#4
Re: creating new Image object
You can do that in the loop - here is a general idea:
VB Code:
Option Explicit
Private Sub Command1_Click()
'add 5 more pictureboxes
AddMorePictures 5
End Sub
Public Sub AddMorePictures(iCount As Integer)
Dim i%
For i = Picture1.UBound + 1 To iCount
Load Picture1(i)
With Picture1(i)
.Picture LoadPicture("...")
.Move '...
.Visible = True
End With
Next i
End Sub
-
Dec 30th, 2005, 11:20 AM
#5
Thread Starter
Hyperactive Member
Re: creating new Image object
thanks i'll try that and get back to you. sorry about the delay in replying but i couldnt find the thread
-
Dec 30th, 2005, 11:23 AM
#6
Re: creating new Image object
 Originally Posted by joel2892
... i couldnt find the thread
In case you don't know you can subscribe to a thread.
-
Dec 30th, 2005, 02:45 PM
#7
Thread Starter
Hyperactive Member
Re: creating new Image object
Done. thanks for that piece of advice.
-
Dec 30th, 2005, 03:23 PM
#8
Re: creating new Image object
Not at all.
-
Dec 31st, 2005, 05:51 AM
#9
Thread Starter
Hyperactive Member
Re: creating new Image object
when i use the code above it says method or data member not found(i think) on this bit of code
what could be causing this problem
Last edited by joel2892; Dec 31st, 2005 at 08:17 AM.
Reason: got the wrong code
-
Dec 31st, 2005, 08:18 AM
#10
Thread Starter
Hyperactive Member
Re: creating new Image object
-
Dec 31st, 2005, 09:20 AM
#11
Re: creating new Image object
If you want to use Control Array then set Picture1.Index = 0 (zero) in the properties window.
-
Dec 31st, 2005, 10:57 AM
#12
Thread Starter
Hyperactive Member
Re: creating new Image object
i have adapted your code to use the imagebox. but when it runs i get error 13 type mismatch and it highlights the commented line in this code. Why?
VB Code:
Public Sub AddMorePictures(iCount As Integer)
CommonDialog1.ShowOpen
pictureload = CommonDialog1.FileName
For i = Image4.UBound + 1 To iCount
Load Image4(i)
'Image1(i).Picture pictureload
Image1(i).Move 12, 34, 56, 67
Image1(i).Visible = True
Next i
End Sub

BTW the commented line isnt commented out in my app that is just to show where the error occures
-
Dec 31st, 2005, 11:43 AM
#13
Re: creating new Image object
Didn't you see this line in one of my previous posts:
Image1(Image1.Ubound).Picture = LoadPicture("full_path_goes_here")
So, what you need is to properly use LoadPicture() function:
VB Code:
Image1(i).Picture = LoadPicture("c:\temp\some_image.bmp")
'or
Image1(i).Picture = LoadPicture(App.Path & "\Images\some_image.bmp")
'or whatever else the path could be.
-
Jan 1st, 2006, 05:15 AM
#14
Thread Starter
Hyperactive Member
Re: creating new Image object
i have used your code and i still get an error on the.loadpicture line(error 13, type mismatch) anyone know why
VB Code:
Public Sub AddMorePictures(iCount As Integer)
CommonDialog1.ShowOpen
pictureload = CommonDialog1.FileName
For i = Image4.UBound + 1 To iCount
Load Image4(i)
'Image1(i).LoadPicture pictureload
Image1(i).Move 12, 34, 56, 67
Image1(i).Visible = True
Next i
End Sub
-
Jan 1st, 2006, 09:21 AM
#15
Re: creating new Image object
How could NOT see the CORRECT syntax I gave you more than once?
Here we go again:
this is what you have:
Image1(i).LoadPicture pictureload
this is what yiou NEED:
Image1(i).Picture = LoadPicture(pictureload)
-
Jan 2nd, 2006, 05:37 AM
#16
Thread Starter
Hyperactive Member
Re: creating new Image object
yeah. thanks. i think my main problem was when it did work the coordinates were so small i couldnt see it well. but it works fine now apart from the image only loads once and if a new file is selected the old one is overwritten. do i just need to set up a for loop inside which could load new coordinates each time. Thanks again
-
Jan 2nd, 2006, 09:26 AM
#17
Re: creating new Image object
Great! You're welcome.
-
Jan 2nd, 2006, 01:58 PM
#18
Thread Starter
Hyperactive Member
Re: creating new Image object
so what about the problems i've got
-
Jan 2nd, 2006, 02:18 PM
#19
Re: creating new Image object
How do you want to place new controls? Vertically or horizontally?
This way:
A
A
A
A
A
Or this way:
AAAAA
-
Jan 3rd, 2006, 05:49 AM
#20
Thread Starter
Hyperactive Member
Re: creating new Image object
can it be done when the user clicks on a location on the screen a image is added
-
Jan 3rd, 2006, 08:59 AM
#21
Re: creating new Image object
Would this sample work for you?
VB Code:
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Load Image1(Image1.UBound + 1)
With Image1(Image1.UBound)
.Move X, Y
.Visible = True
End With
End Sub
-
Jan 3rd, 2006, 10:51 AM
#22
Thread Starter
Hyperactive Member
Re: creating new Image object
 Originally Posted by RhinoBull
Would this sample work for you?
VB Code:
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Load Image1(Image1.UBound + 1)
With Image1(Image1.UBound)
.Move X, Y
.Visible = True
End With
End Sub
yeah. thats great. havent tried it yet but looks good. thanks
-
Jan 3rd, 2006, 11:29 AM
#23
Re: creating new Image object
-
Jan 4th, 2006, 10:57 AM
#24
Thread Starter
Hyperactive Member
Re: creating new Image object
that works great. a few problems to start with but all my fault as per usual. one issue still remains though. when you put an image in place it is always behind the richtextbox even when i have changed this using send to back and bring to front. any way round this. Thanks
-
Jan 13th, 2006, 10:47 AM
#25
Thread Starter
Hyperactive Member
Re: creating new Image object
-
Jan 13th, 2006, 11:58 AM
#26
Re: creating new Image object
Image control is a windowless control (doesn't have a hWnd property) and therefore cannot be on top of any window 9such button, rtb, picturebox, etc). You may either use Picturebox instead OR place Image control inside Picturebox control.
-
Jan 13th, 2006, 12:36 PM
#27
Thread Starter
Hyperactive Member
Re: creating new Image object
 Originally Posted by RhinoBull
place Image control inside Picturebox control.
how do i do that
-
Jan 13th, 2006, 12:39 PM
#28
Re: creating new Image object
 Originally Posted by joel2892
how do i do that
Just click on the ImageList on your toolbox bar and draw it inside of the picture control.
-
Jan 13th, 2006, 12:55 PM
#29
Thread Starter
Hyperactive Member
Re: creating new Image object
what does the ImageList logo look like i cant find it
-
Jan 13th, 2006, 01:14 PM
#30
Re: creating new Image object
 Originally Posted by joel2892
what does the ImageList logo look like i cant find it
ImageList is included under Microsoft Windows Common Controls 6.0.
-
Jan 13th, 2006, 01:16 PM
#31
Re: creating new Image object
 Originally Posted by Hack
Just click on the ImageList on your toolbox bar and draw it inside of the picture control.
I meant Image Control - not ImageList...
-
Jan 13th, 2006, 01:18 PM
#32
Re: creating new Image object
 Originally Posted by joel2892
how do i do that
Simply select your Image control and press CTRL+X and then select your picturebox and press CTRL+V - typical Windows CUT and PASTE operation.
-
Jan 13th, 2006, 02:17 PM
#33
Thread Starter
Hyperactive Member
Re: creating new Image object
-
Jan 13th, 2006, 02:19 PM
#34
Re: creating new Image object
 Originally Posted by RhinoBull
I meant Image Control - not ImageList...
Actually, so did I.
-
Jan 13th, 2006, 02:32 PM
#35
Thread Starter
Hyperactive Member
Re: creating new Image object
so i put the imagebox in the picturebox but how do i need to edit the code so that they both move like the image did
-
Jan 15th, 2006, 05:23 AM
#36
Thread Starter
Hyperactive Member
Re: creating new Image object
-
Jan 15th, 2006, 11:58 AM
#37
Re: creating new Image object
this is an example using 2 pictureboxes (array members) and 1 RTB, posted by Rhino in some post, i modified it with RTB for you.
VB Code:
Option Explicit
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Declare Function SendMessageLong Lib "user32" _
Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Picture1_MouseDown(Index As Integer, Button As Integer, _
Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
ReleaseCapture
SendMessageLong Picture1(Index).hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End If
End Sub
Private Sub rtb_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
ReleaseCapture
SendMessageLong rtb.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End If
End Sub
it will also help you in moving the objects at run-time.
hope it helps you.
-
Jan 15th, 2006, 01:36 PM
#38
Thread Starter
Hyperactive Member
Re: creating new Image object
thats cool but for this line of the code
VB Code:
Private Function SetAlignment(lHwnd As Long, ByVal eAlign As ERECParagraphAlignmentConstants
user defined type not defined why is this
-
Jan 15th, 2006, 01:47 PM
#39
Re: creating new Image object
"ERECParagraphAlignmentConstants" TYPE is missing from your code. you need to declare it before that API.
-
Jan 15th, 2006, 02:02 PM
#40
Thread Starter
Hyperactive Member
Re: creating new Image object
and how do i declare that. sorry i'm not well up on that sort of stuff
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
|