dcsimg
Results 1 to 25 of 25

Thread: [RESOLVED] Image Control with Picture on top of a Picturebox

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Resolved [RESOLVED] Image Control with Picture on top of a Picturebox

    Can an image control with a picture in it be displayed on top of a Picturebox without the image control being a child control of the Picturebox?

    Problem: I need to show several pictures which are in image controls but if I make the Picturebox the parent control then when the Picturebox is cleared (Picture1.Cls) all of the image controls flicker

    NOTE: pictures cannot be BitBlt or otherwise drawn on Picture1 as they will be erased when Picture1.Cls is executed.

    I guess what I am looking for are pictureboxs with the pictures in them and a transparent background then instead of putting them on Picture1 as a child controls I could just move them to their position and make their ZOrder 0
    Last edited by jmsrickland; Aug 7th, 2013 at 05:15 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,869

    Re: Image Control with Picture on top of a Picturebox

    The Image control is a lightweight control like a Label. It has no hDC and uses the hDC of its container.

    This means that no, you can't display Image controls contained in a Form "on top of" a PictureBox contained in the Form since a PictureBox has its own hDC.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Image Control with Picture on top of a Picturebox

    What about a user control image control. Doesn't it have the hDC and a handle as well? If so, then couldn't the user control have a transparent background and "sit" on top of the picturebox?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,869

    Re: Image Control with Picture on top of a Picturebox

    Sounds like you want to have a talk with that guy who tries to make sprites out of UserControls.

  5. #5
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,113

    Re: Image Control with Picture on top of a Picturebox

    Quote Originally Posted by jmsrickland View Post
    What about a user control image control. Doesn't it have the hDC and a handle as well? If so, then couldn't the user control have a transparent background and "sit" on top of the picturebox?
    Even if doable, it would flicker just as much as the other things you have tried. As dilettante says, you are effectively attempting 'sprite'-like behaviour. You may as well bite the bullet and go for a BitBlt solution, using an off-screen buffer for performance and manually tracking the 'boundaries' of your sprites for the purpose of mouse interaction (assuming that's what you have in mind).

    If it's a personal project (i.e. not for distribution), you may want to look at the vbRichClient5 stuff. This stuff may be more easily do-able over that framework.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Image Control with Picture on top of a Picturebox

    It is doable and it (they since more than one) won't flicker either


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,113

    Re: Image Control with Picture on top of a Picturebox

    Did I interpret correctly that the user can move these images around? If so, I'm very surprised that it doesn't flicker...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  8. #8
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Image Control with Picture on top of a Picturebox

    JMS

    It seems that transparency is needed.

    Thus, simply putting the Image control inside of its own PictureBox (admittedly overkill)
    would seem to be unsatisfactory.

    Could you possibly post a screenshot of your original situation and describe the nature
    of the flicker problem

    Spoo

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Image Control with Picture on top of a Picturebox

    It's a Push-Pin project. The user loads a picture of what ever he wants (the sample uses a map of the USA) into a Picturebox. Now the user can drag-n-drop images (Image Control) of Pins here and there over the picture and place them where ever he wants to position them. This does not cause flickering and the movement is very smooth. Because I need transparency I have to use an Image Control for the pins and they have to be child controls of the picture otherwise I can't show them on top of the picturebox.

    The flickering problem comes in when the user drags a rubber-band (I call it a rubber-band but maybe it's something else) across the top of the picturebox. During the dragging of the rubber-band all the pins flicker because the band drawing process requires the picturebox to be cleared (Picture1.Cls) so as to erase the lines as the band is being drawn otherwise you will see a mess. It's not the drawing of the band that causes flickering but rather the Picture1.Cls.

    I have a rubber-band method that won't cause flickering which uses XORing instead of .Cls but I don't like it's appearance as it will contain different colors bexause it is XORed with many different colors of the picture. The band I want to use is a red dashed-line type but to have it a single color of red then I have to draw it as dotted-lines and use the Picture1.Cls.

    If the image control was not a child control it wouldn't flicker and that is why I asked about a user control image control because it can have transparency and also "sit" on top of the picturebox. It also needs stretch capabilities so the user can make the pins larger or smaller. I don't know how to make a user control like this.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Image Control with Picture on top of a Picturebox

    JMS

    Helpful description of the situation, except for "rubber band"
    What does it mean?

    Something like a rectangle with dashed perimeter that grows as the
    mouse is dragged (in preparation for zooming)?

    Something else?

    Spoo

  11. #11
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,113

    Re: Image Control with Picture on top of a Picturebox

    Can you describe what you mean by a rubber-band, please, jms? Is this a rectangle that the user draws with the mouse?

    EDIT: Posts crossed!
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Image Control with Picture on top of a Picturebox

    I call it a rubber-band. It's what Spoo and Colin66 posted; a rectangle that the user draws to encompass an area to be marked off as an area for copying.

    What is the correct term for rubber band
    Attached Images Attached Images  
    Last edited by jmsrickland; Aug 8th, 2013 at 12:15 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  13. #13
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,113

    Re: Image Control with Picture on top of a Picturebox

    Just use a shape control that is also a child of the picturebox and something like

    Code:
    Private mBandSizing As Boolean
    
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        mBandSizing = True
        Shape1.Move X, Y, 1, 1
    End Sub
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If mBandSizing Then
            Shape1.Width = X - Shape1.Left
            Shape1.Height = Y - Shape1.Top
        End If
    End Sub
    
    Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        mBandSizing = False
    End Sub
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  14. #14
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: Image Control with Picture on top of a Picturebox

    Quote Originally Posted by jmsrickland View Post
    What is the correct term for rubber band
    Selection Rectangle.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Image Control with Picture on top of a Picturebox

    See edited post #12 included a picture


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Image Control with Picture on top of a Picturebox

    @ColinE66

    Although using Shape is a good idea it still flickers the pins


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  17. #17
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,113

    Re: Image Control with Picture on top of a Picturebox

    Ah, yes - just tried it and see what you mean....
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  18. #18
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,113

    Re: Image Control with Picture on top of a Picturebox

    OK, for the Rubber band only, create a user control that contains just a shape. Set the UC to be transparent and then;

    Code:
    Private mBandSizing As Boolean
    
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        mBandSizing = True
        UserControl1.Move X, Y, 1, 1
    End Sub
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If mBandSizing Then
            With UserControl1
                .Move .Left, .Top, X - .Left, Y - .Top
            End With
        End If
    End Sub
    
    Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        mBandSizing = False
    End Sub
    Presto! No flicker....

    EDIT: Oh and no need for Picture1.cls
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  19. #19
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,113

    Re: Image Control with Picture on top of a Picturebox

    Sorry jms - forgot the code for the UC

    Code:
    Private Sub UserControl_Resize()
        Shape1.Move 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight
    End Sub
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  20. #20
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,113

    Re: Image Control with Picture on top of a Picturebox

    Sory jms - don't quite understand your sentence above? I knocked something up with a Picturebox (for the map) that contains a single UC as described in my previous post and several Image Controls (for the pins). Obviously, the Image Controls can be resized to stretch the pin images, if needed. Am I missing something?
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  21. #21

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Image Control with Picture on top of a Picturebox

    OK, never mind. I deleted that post as it was not the correct statement. I wasn't thinking when I asked about the stretch since I already have it with the Image Controls Push-Pins.

    Your UserControl is great! Thank you

    What I should have asked is can you make so that the user can draw the rectangle in any direction? If you drag from left to right and top to bottom it works OK but try reversing it and it will error out and I know users will want to draw the rectangle starting in any corner


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  22. #22
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,113

    Re: Image Control with Picture on top of a Picturebox

    Yes, I realised that what I posted would cause an error for anything other than a right or down drag. However, I recall you asking about multi-directional dragging in one of your previous threads so I assumed you would be able to handle that part...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  23. #23

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Image Control with Picture on top of a Picturebox

    OK, yes, now that you mentioned it. I'll look back there or find the project that I was working on for that purpose.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  24. #24

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Image Control with Picture on top of a Picturebox

    I'm resolving this thread as my problem has been answered.

    Thanks, Colin, and everyone else for your help


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  25. #25
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,113

    Re: [RESOLVED] Image Control with Picture on top of a Picturebox

    You're welcome....
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width