-
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.
-
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
-
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
-
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
-
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
-
Re: creating new Image object
Quote:
Originally Posted by joel2892
... i couldnt find the thread
In case you don't know you can subscribe to a thread.
-
Re: creating new Image object
Done. thanks for that piece of advice.
-
Re: creating new Image object
-
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 :confused:
-
Re: creating new Image object
-
Re: creating new Image object
If you want to use Control Array then set Picture1.Index = 0 (zero) in the properties window.
-
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
:confused:
BTW the commented line isnt commented out in my app that is just to show where the error occures
-
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.
-
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
-
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)
-
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
-
Re: creating new Image object
Great! You're welcome. :wave:
-
Re: creating new Image object
so what about the problems i've got
-
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
-
Re: creating new Image object
can it be done when the user clicks on a location on the screen a image is added
-
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
-
Re: creating new Image object
Quote:
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
-
Re: creating new Image object
-
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
-
Re: creating new Image object
-
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.
-
Re: creating new Image object
Quote:
Originally Posted by RhinoBull
place Image control inside Picturebox control.
how do i do that
-
Re: creating new Image object
Quote:
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.
-
Re: creating new Image object
what does the ImageList logo look like i cant find it
-
Re: creating new Image object
Quote:
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.
-
Re: creating new Image object
Quote:
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...
-
Re: creating new Image object
Quote:
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. :)
-
Re: creating new Image object
-
Re: creating new Image object
Quote:
Originally Posted by RhinoBull
I meant Image Control - not ImageList...
Actually, so did I. :blush:
-
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
-
Re: creating new Image object
-
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.
-
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
-
Re: creating new Image object
"ERECParagraphAlignmentConstants" TYPE is missing from your code. you need to declare it before that API.
-
Re: creating new Image object
and how do i declare that. sorry i'm not well up on that sort of stuff