[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.
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.
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.
Re: Image Control with Picture on top of a Picturebox
Originally Posted by jmsrickland
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...
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.
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.
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
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.
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...
Re: Image Control with Picture on top of a Picturebox
Originally Posted by jmsrickland
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
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.
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.
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...
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...
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.
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...
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.
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.