Page 1 of 2 12 LastLast
Results 1 to 40 of 53

Thread: creating new Image object

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Question 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.
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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:
    1. Load Image1(Image1.Ubound + 1)
    2. Image1(Image1.Ubound).Move 100, 100 'you must determine where you want it
    3. Image1(Image1.Ubound).Picture = LoadPicture("full_path_goes_here")
    4. Image1(Image1.Ubound).Visible = True

    To utilize controls collection here is the logic:
    VB Code:
    1. Dim img As Image
    2.  
    3. Set img = Controls.Add("VB.Image", "imgTemp") 'you need to come up with unique sequence to name each new control
    4. img.Picture = LoadPicture("full_path_goes_here")
    5. img.Move ...
    6. img.Visible = True

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    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
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: creating new Image object

    You can do that in the loop - here is a general idea:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     'add 5 more pictureboxes
    5.     AddMorePictures 5
    6. End Sub
    7.  
    8. Public Sub AddMorePictures(iCount As Integer)
    9. Dim i%
    10.  
    11.     For i = Picture1.UBound + 1 To iCount
    12.         Load Picture1(i)
    13.         With Picture1(i)
    14.             .Picture LoadPicture("...")
    15.             .Move '...
    16.             .Visible = True
    17.         End With
    18.     Next i
    19.  
    20. End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    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
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  6. #6

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Re: creating new Image object

    Done. thanks for that piece of advice.
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  8. #8

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Question 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

    VB Code:
    1. picture1.Ubound

    what could be causing this problem
    Last edited by joel2892; Dec 31st, 2005 at 08:17 AM. Reason: got the wrong code
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Re: creating new Image object

    ***bump****
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  11. #11

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Question 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:
    1. Public Sub AddMorePictures(iCount As Integer)
    2. CommonDialog1.ShowOpen
    3. pictureload = CommonDialog1.FileName
    4.     For i = Image4.UBound + 1 To iCount
    5.         Load Image4(i)
    6.        
    7.         'Image1(i).Picture pictureload
    8.         Image1(i).Move 12, 34, 56, 67
    9.         Image1(i).Visible = True
    10.     Next i
    11.  
    12. End Sub

    BTW the commented line isnt commented out in my app that is just to show where the error occures
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  13. #13
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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:
    1. Image1(i).Picture = LoadPicture("c:\temp\some_image.bmp")
    2. 'or
    3. Image1(i).Picture = LoadPicture(App.Path & "\Images\some_image.bmp")
    4. 'or whatever else the path could be.

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Question 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:
    1. Public Sub AddMorePictures(iCount As Integer)
    2. CommonDialog1.ShowOpen
    3. pictureload = CommonDialog1.FileName
    4.     For i = Image4.UBound + 1 To iCount
    5.         Load Image4(i)
    6.        
    7.         'Image1(i).LoadPicture pictureload
    8.         Image1(i).Move 12, 34, 56, 67
    9.         Image1(i).Visible = True
    10.     Next i
    11.  
    12. End Sub
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  15. #15

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    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
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  17. #17

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Re: creating new Image object

    so what about the problems i've got
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  19. #19

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Re: creating new Image object

    can it be done when the user clicks on a location on the screen a image is added
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  21. #21
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: creating new Image object

    Would this sample work for you?
    VB Code:
    1. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     Load Image1(Image1.UBound + 1)
    3.     With Image1(Image1.UBound)
    4.         .Move X, Y
    5.         .Visible = True
    6.     End With
    7. End Sub

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Question Re: creating new Image object

    Quote Originally Posted by RhinoBull
    Would this sample work for you?
    VB Code:
    1. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     Load Image1(Image1.UBound + 1)
    3.     With Image1(Image1.UBound)
    4.         .Move X, Y
    5.         .Visible = True
    6.     End With
    7. End Sub
    yeah. thats great. havent tried it yet but looks good. thanks
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  23. #23

  24. #24

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    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
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Re: creating new Image object

    ***bump***
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  26. #26
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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.

  27. #27

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Question Re: creating new Image object

    Quote Originally Posted by RhinoBull
    place Image control inside Picturebox control.
    how do i do that
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  28. #28
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  29. #29

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Re: creating new Image object

    what does the ImageList logo look like i cant find it
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  30. #30
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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.
    Show Appreciation. Rate Posts.

  31. #31

  32. #32

  33. #33

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Re: creating new Image object

    oh right. i'll try that
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  34. #34
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: creating new Image object

    Quote Originally Posted by RhinoBull
    I meant Image Control - not ImageList...
    Actually, so did I.

  35. #35

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    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
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  36. #36

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Re: creating new Image object

    anyone
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  37. #37
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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:
    1. Option Explicit
    2.  
    3. Private Const WM_NCLBUTTONDOWN = &HA1
    4. Private Const HTCAPTION = 2
    5.  
    6. Private Declare Function SendMessageLong Lib "user32" _
    7.         Alias "SendMessageA" ( _
    8.             ByVal hwnd As Long, _
    9.             ByVal wMsg As Long, _
    10.             ByVal wParam As Long, _
    11.             ByVal lParam As Long) As Long
    12.             Private Declare Function ReleaseCapture Lib "user32" () As Long
    13.  
    14. Private Sub Picture1_MouseDown(Index As Integer, Button As Integer, _
    15.                                Shift As Integer, x As Single, y As Single)
    16.                                
    17. If Button = vbLeftButton Then
    18.         ReleaseCapture
    19.         SendMessageLong Picture1(Index).hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
    20.     End If
    21. End Sub
    22.  
    23. Private Sub rtb_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    24. If Button = vbLeftButton Then
    25.         ReleaseCapture
    26.         SendMessageLong rtb.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
    27.     End If
    28. End Sub
    it will also help you in moving the objects at run-time.

    hope it helps you.
    Show Appreciation. Rate Posts.

  38. #38

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Re: creating new Image object

    thats cool but for this line of the code
    VB Code:
    1. Private Function SetAlignment(lHwnd As Long, ByVal eAlign As ERECParagraphAlignmentConstants
    user defined type not defined why is this
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

  39. #39
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: creating new Image object

    "ERECParagraphAlignmentConstants" TYPE is missing from your code. you need to declare it before that API.
    Show Appreciation. Rate Posts.

  40. #40

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    292

    Re: creating new Image object

    and how do i declare that. sorry i'm not well up on that sort of stuff
    'Rarely is the question asked: Is our children learning?' George Bush

    visit my website @ www.freewebs.com/vbplanet

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width