Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Sep 2007
    Location
    Chatham, Kent, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PictureBox (VB6)

    Evening all. I've been away for a while but they let me out so I'm back!

    I've been playing about with a bit of VB code which puts bmps into picture boxes. It might eventually become a fun little game!

    This snippet puts the bmp into the picture box from a variable:

    Private Sub Command1_Click()

    Dim objPic As Picture ' Dim Variable
    Set objPic = LoadPicture("C:Harvey00.bmp") ' Load variable
    Picture1 = LoadPicture() ' Clear Picture1
    Set Picture1.Picture = objPic ' Load Picture1

    End Sub

    And this puts the bmp in from the clipboard:

    Private Sub Command2_Click()

    Clipboard.Clear ' Clear Clipboard
    Clipboard.SetData LoadPicture("C:Harvey01.BMP") ' Load Clipboard
    Picture1 = LoadPicture() ' Clear Picture1
    Picture1 = Clipboard.GetData() ' Load Picture1

    End Sub

    What I'd like to do and can't is load the variable from the clipboard and then load the picture box from the variable.

    Any offers of suggestions of what I need to read up on to achieve this would be gratefully accepted.

    Regards

    Graeme

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PictureBox (VB6)

    This demo might be of some help. It uses an Image control on a (Excel VBA) form. You can type the "variable" (full path of the graphic) into the textbox, click "Copy to clipboard" then click "Load Picture" to read the clipboard "variable" and load the corresponding image.

    Alan

  3. #3
    2 Star Lounger
    Join Date
    Sep 2007
    Location
    Chatham, Kent, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PictureBox (VB6)

    Thanks for getting back Alan.

    That works lovely (of course!) but in my programme I already have the bmp on the clipboard.

    I need to be able to get the bmp into the variable (objPic) from the clipboard without having to type a file name.

    Hope that makes sense!

    Regards

    Graeme

  4. #4
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PictureBox (VB6)

    Sorry, I interpreted the term "variable" as the file path to the picture. Although I haven't delved into what you're wanting to do, perhaps the article: How to add Cut, Copy and Paste Functions might provide some insight.

    Alan

  5. #5
    2 Star Lounger
    Join Date
    Sep 2007
    Location
    Chatham, Kent, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PictureBox (VB6)

    Thanks for that Alan.

    Interesting article but I'm ok with the cutting and pasting thing. I think I've been away too long, I've forgotten how to express myself!!!

    The programme I'm working on reaches a stage where a bit map picture is placed on the clipboard. This is all ok. Next I need to put the contents of the clipboard, the bit map picture, into the previously declared variable objPic.

    So my question is, can this be done? Is there a Statement, Function or Method in Visual Basic 6 which will transfere the contents of the clipboard into a variable declared "As Picture"? Can I code a copy of the clipboard, if it's a bit map picture into a variable in order to do further stuff with it without typing the bmp's file name?

    I've looked in the help and I've looked in some books for such a command but all to no avail. I can't believe this can't be done! So If anyone knows the code I'm after, a hint in the right direction would be great.

    Regards

    Graeme

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: PictureBox (VB6)

    Try

    Dim objPic As IPictureDisp
    Set objPic = Clipboard.GetData()

    You need a reference in Project | References to the OLE Automation library (STDOLE2.TLB).

  7. #7
    2 Star Lounger
    Join Date
    Sep 2007
    Location
    Chatham, Kent, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PictureBox (VB6)

    Ah ha!!! IPictureDisp

    It's great to be back!

    Thanks Hans

    Regards

    Graeme

  8. #8
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PictureBox (VB6)

    I see ol' faithful found the answer for you. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> I think I misinterpreted your intentions. I now see, after the horse has bolted, that you wanted an object variable to actually hold the picture for further manipulation. Anyway, glad you got the solution.

    Alan

  9. #9
    2 Star Lounger
    Join Date
    Sep 2007
    Location
    Chatham, Kent, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PictureBox (VB6)

    Aye! The Man came up with the goods!

    Thanks for your interest though.

    Regards

    Graeme

Posting Permissions

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