Question

Dragging objects over containers

Asked by: motile

Dear friends,

I'm dragging an Image control by changing it's Left and Top properties as the cursor moves (the object itself is moving instead of just the rectangle that surrounds it). It's like moving the cards in the Solitaire game.

The problem is that I have several containers (PictureBox controls) on the form, and I need to drag an Image control from one PictureBox to another.
The Image control is imprisoned inside it's container. Although I can get it out if I change it's container from the PictureBox to the form and change it's coordinates to match it's location on the form, still there is the matter of the display. When the Image control is half way from the PictureBox to the form, only the area of the Image that is over the form is seen, and the area that is supposed to be over the PictureBox is hidden underneath it, because the PictureBox is no longer it's container.

What should I do? Is there a friendly way of dragging objects over containers?

I'll appreciate your help on this matter.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2000-08-23 at 04:16:17ID11081865
Topic

Visual Basic Programming

Participating Experts
4
Points
200
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Drag a rectangle
    My question goes like this : I have a rectangle drawn in my client area. Let's say its size is 5*5, and its name is m_Rect (of type CRect). Now, assume the client area contains some other things. I need to write something (in MFC of course) that makes it capable for the user...
  2. Drawing rectangles on picturebox
    Hi, I counter a problem when I draw a set of rectangles on picturebox, using line method. the rectangles' height are 30 and width are 10, but the result is not what I expect. some rectangles are slim and some are slightly thicker, though they are with same width value. I...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: v_natraj_vPosted on 2000-08-23 at 04:33:21ID: 4035426

I give you an idea:
When the user starts dragging the container you create a Shape Control at runtime and move that Shape Control as the mouse moves.  When the user leave the mouse button, make that shapecontrol invisible and move your Picture box object.

I think this will solve yr problem.

Cheers !!!
Natraj

 

by: andyclapPosted on 2000-08-23 at 04:57:04ID: 4035586

Images, because they're not real windows, automatically sit behind any 'real-windowed' contols on the form.
This also goes for labels and shapes.
Even zorder won't help you here.
You may need to use a picture control, copy the image control's picture into it, then hide the image control. The problem with this is of course that pictures don't do transparency or stretching easily.

 

by: VbmasterPosted on 2000-08-23 at 05:53:57ID: 4036367

Here's a solution that will allow you to move any object. It does this by drawing directly onto the screen.

Option Explicit

'API Constants
Private Const VK_LBUTTON = &H1
Private Const PS_SOLID = 0
Private Const R2_NOTXORPEN = 10
Private Const BLACK_PEN = 7

'API Types
Private Type RECT
  Left As Long
  Top As Long
  right As Long
  bottom As Long
End Type

Private Type POINTAPI
  X As Long
  Y As Long
End Type

'API Declares
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetROP2 Lib "gdi32" (ByVal hdc As Long, ByVal nDrawMode As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Private Function DragObject(lLeft As Long, lTop As Long, lWidth As Long, lHeight As Long, OwnerhWnd As Long, ScaleMode As ScaleModeConstants, Optional lMinLeft As Long, Optional lMinTop As Long, Optional lMaxLeft As Long, Optional lMaxTop As Long) As Boolean

  Dim pt As POINTAPI
  Dim lOffsetX As Long
  Dim lOffsetY As Long
  Dim rtRectangle As RECT
  Dim ptPrevious As POINTAPI
  Dim ptOriginal As POINTAPI
  Dim bRestricted As Boolean
 
  'If the object to be moved is restricted to
  'a certain screen area then calculat the
  'screen coordinates
  If (lMinLeft > 0) Or (lMinTop > 0) Or (lMaxLeft > 0) Or (lMaxTop > 0) Then
    bRestricted = True
    lMinLeft = ScaleX(lMinLeft, ScaleMode, vbPixels)
    lMinTop = ScaleX(lMinTop, ScaleMode, vbPixels)
    lMaxLeft = ScaleX(lMaxLeft, ScaleMode, vbPixels)
    lMaxTop = ScaleX(lMaxTop, ScaleMode, vbPixels)
    pt.X = lMinLeft
    pt.Y = lMinTop
    Call ClientToScreen(hwnd, pt)
    lMinLeft = pt.X
    lMinTop = pt.Y
    pt.X = lMaxLeft
    pt.Y = lMaxTop
    Call ClientToScreen(hwnd, pt)
    lMaxLeft = pt.X
    lMaxTop = pt.Y
  End If
 
  'Convert the parameters to pixels
  lLeft = ScaleX(lLeft, ScaleMode, vbPixels)
  lWidth = ScaleX(lWidth, ScaleMode, vbPixels)
  lTop = ScaleY(lTop, ScaleMode, vbPixels)
  lHeight = ScaleY(lHeight, ScaleMode, vbPixels)
 
  'Convert the position to relative screen
  pt.X = lLeft
  pt.Y = lTop
  Call ClientToScreen(hwnd, pt)
  lLeft = pt.X
  lTop = pt.Y
 
  'Store the initial cursor position
  Call GetCursorPos(ptOriginal)
  pt = ptOriginal
 
  'Calculate the offset of the mouse position
  'compared to the upper-left corner of the
  'rectangle to be drawn
  lOffsetX = ptOriginal.X - lLeft
  lOffsetY = ptOriginal.Y - lTop
 
  'Calculate the first rectangle
  With rtRectangle
    .Left = lLeft
    .Top = lTop
    .right = lLeft + lWidth
    .bottom = lTop + lHeight
  End With
 
  'Draw the first rectangle
  Call DrawDragRectangle(rtRectangle.Left, rtRectangle.Top, rtRectangle.right, rtRectangle.bottom, 3)
 
  'Redraw the rectangle whenever the user
  'moves the mouse as long as the left
  'mouse button is pressed
  Do While (GetKeyState(VK_LBUTTON) < 0)
    Call GetCursorPos(pt)
    If (pt.X <> ptPrevious.X) Or (pt.Y <> ptPrevious.Y) Then
      ptPrevious.X = pt.X
      ptPrevious.Y = pt.Y
     
      'Erase the previous drag rectangle
      Call DrawDragRectangle(rtRectangle.Left, rtRectangle.Top, rtRectangle.right, rtRectangle.bottom, 3)
     
      'Recalculate the rectangle to draw
      With rtRectangle
        .Left = pt.X - lOffsetX
        .Top = pt.Y - lOffsetY
        If (bRestricted) Then
          If (.Left < lMinLeft) Then
            .Left = lMinLeft
          ElseIf (.Left > lMaxLeft) Then
            .Left = lMaxLeft
          End If
          If (.Top < lMinTop) Then
            .Top = lMinTop
          ElseIf (.Top > lMaxTop) Then
            .Top = lMaxTop
          End If
        End If
        .right = .Left + lWidth
        .bottom = .Top + lHeight
      End With
     
      'Draw the new rectangle onto the screen
      Call DrawDragRectangle(rtRectangle.Left, rtRectangle.Top, rtRectangle.right, rtRectangle.bottom, 3)
    End If
    DoEvents
  Loop
 
  'Erase the previous drag rectangle
  Call DrawDragRectangle(rtRectangle.Left, rtRectangle.Top, rtRectangle.right, rtRectangle.bottom, 3)
 
  'Convert the position to relative object's container
  lLeft = rtRectangle.Left
  lTop = rtRectangle.Top
  pt.X = lLeft
  pt.Y = lTop
  Call ScreenToClient(hwnd, pt)
  lLeft = pt.X
  lTop = pt.Y
   
  'Convert the parameters back from pixels
  'to the object's container's scalemode
  lLeft = ScaleX(lLeft, vbPixels, ScaleMode)
  lTop = ScaleY(lTop, vbPixels, ScaleMode)
  lWidth = ScaleX(lWidth, vbPixels, ScaleMode)
  lHeight = ScaleY(lHeight, vbPixels, ScaleMode)
 
  'Notify if this object was moved
  DragObject = (pt.X <> ptOriginal.X) Or (pt.Y <> ptOriginal.Y)
 
End Function

Private Sub DrawDragRectangle(ByVal X As Long, ByVal Y As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal lWidth As Long)

  'Draw a rectangle using the Win32 API

  Dim hdc As Long
  Dim hPen As Long
 
  hdc = GetDC(0)
  hPen = CreatePen(PS_SOLID, lWidth, &HE0E0E0)
  Call SelectObject(hdc, hPen)
  Call SetROP2(hdc, R2_NOTXORPEN)
  Call Rectangle(hdc, X, Y, X1, Y1)
  Call SelectObject(hdc, GetStockObject(BLACK_PEN))
  Call DeleteObject(hPen)
  Call SelectObject(hdc, hPen)
  Call ReleaseDC(0, hdc)
   
End Sub



Now you probably want an example too. And here it is...

1) Create a form and add a picturebox to the form.
2) Paste the function, API's and stuff into the form's (Declarations) part
3) Edit the Piture1_MouseDown event to this...

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

  Dim Top As Long
  Dim Left As Long
  Dim Width As Long
  Dim Height As Long
 
  Left = Picture1.Left
  Top = Picture1.Top
  Width = Picture1.Width
  Height = Picture1.Height
  If (DragObject(Left, Top, Width, Height, Picture1.Container.hwnd, Picture1.Container.ScaleMode, 0, 0, Me.ScaleWidth - Picture1.Width, Me.ScaleHeight - Picture1.Height)) Then
    Call Picture1.Move(Left, Top, Width, Height)
  End If

End Sub


Now you can click on the picturebox and be allowed to move it to anywhere on the form. Notice the picturebox is restricted to the form, so you can not move the picturebox outside the form. This is done by the lMinLeft/lMinTop/lMaxLeft/lMaxTop parameters. It should be fairly easy to use this solution, but if you need any more info let me know.

 

by: amebaPosted on 2000-08-23 at 07:24:53ID: 4037569

You 'll have to use some other control instead of Image.
Here is the quick example

' add three Pictureboxes and paste this code
Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Type POINTAPI
    X As Long
    Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Dim startx As Single, starty As Single
Dim moving As Boolean

Private Sub Form_Load()
    Picture1.Picture = Me.Icon
    Picture1.AutoSize = True
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim ptTemp As POINTAPI
    If Button = vbLeftButton Then
        Dim bdrx As Long, bdry As Long
        getBorderXY Picture1, bdrx, bdry
        startx = X + bdrx * 15
        starty = Y + bdry * 15
       
        GetCursorPos ptTemp
        Picture1.Visible = False
        SetParent Picture1.hwnd, 0&
        Picture1.Move ptTemp.X * 15 - startx, ptTemp.Y * 15 - starty
        Picture1.Visible = True
       
        SetCapture Picture1.hwnd
        moving = True
    End If
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim ptTemp As POINTAPI
    If moving And Button = vbLeftButton Then
        GetCursorPos ptTemp
        Picture1.Move ptTemp.X * 15 - startx, ptTemp.Y * 15 - starty
    End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim ptTemp As POINTAPI
    If moving And Button = vbLeftButton Then
        moving = False
        ReleaseCapture
       
        GetCursorPos ptTemp
       
        Picture1.Visible = False
       
        Dim NewContainer As Object ' form or control
        Dim HwndNewContainer As Long
        Dim ptNewContainer As POINTAPI
        HwndNewContainer = WindowFromPoint(ptTemp.X, ptTemp.Y)
       
        ' get new container
        If HwndNewContainer = Picture2.hwnd Then
            Set NewContainer = Picture2
        ElseIf HwndNewContainer = Picture3.hwnd Then
            Set NewContainer = Picture3
        ElseIf HwndNewContainer = Me.hwnd Then
            Set NewContainer = Me
        Else
            Set NewContainer = Me
            Beep
        End If

'        SetParent Picture1.hwnd, NewContainer.hwnd
        Set Picture1.Container = NewContainer
        ScreenToClient NewContainer.hwnd, ptTemp
        Picture1.Move ptTemp.X * 15 - startx, ptTemp.Y * 15 - starty
        Picture1.Visible = True
    End If
End Sub

Private Sub getBorderXY(Control As Control, bdrx As Long, bdry As Long)
    ' calculate border
    'bdrx = 2
    'bdry = 2
    Dim ptContainer As POINTAPI
    Dim ptControl As POINTAPI
    ClientToScreen Control.Container.hwnd, ptContainer
    ClientToScreen Control.hwnd, ptControl
   
    bdrx = ptControl.X - (ptContainer.X + Control.Left / 15)
    bdrx = ptControl.Y - (ptContainer.Y + Control.Top / 15)
End Sub

 

by: motilePosted on 2000-08-23 at 14:32:57ID: 4044266

Dear friends,

First, thank you for your kind answers.

Vbmaster, your code does not work. I added another PictureBox and used it as a container for the first one. I could not drag Picture1 out of Picture2.

ameba, your code works fine, but - as andyclap mentioned - picture boxes don't do transparency. My pictures are not rectangled and I don't want to see the background of the PictureBox.

Besides, I have a large number of pictures and a control that is lighter than PictureBox is preferable.

Is there a way to solve this thing?...

 

by: VbmasterPosted on 2000-08-23 at 15:34:10ID: 4044729

I found one bug where all "hWnd" should be "OwnerhWnd". Silly me. ,)

With my current code you should be able to move the image control outside the picturebox but it will not change the container incase you move the control "onto" another control. For this you will need to run WindowFromPoint API with the cursor position (GetCursorPos API) to get the hWnd of the control the mouse cursor is over, and then use the SetParent API to change the container, or you can loop thru all controls on the form using something like...

Dim Control As Control

If (Me.hWnd = [the_hwnd_given_from_windowfrompoint]) Then
  Set Image1.Container = Me
Else
  For Each Control In Formname.Controls
    If (Not (TypeOf Control Is Line)) Then
      If (Control.hWnd = [the_hwnd_given_from_windowfrompoint]) Then
        Set Image1.Container = Control
        Exit For
      End If
    End If
  Next
End If

 

by: amebaPosted on 2000-08-23 at 15:37:14ID: 4044771

To pass control anywhere and have it on-top, it must be 'heavy' control, with Hwnd.

Maybe this can work - only one temporary picture control:

In Image1_MouseDown:
Hide your image control. Show picturebox picTemp and move it around

In Image1_MouseDown:
When user drops picTemp, show your Image control, change its container and set its position.
Hide picTemp for later use.

What do you thank?

 

by: amebaPosted on 2000-08-23 at 15:38:07ID: 4044786

corr.
>What do you thank?
What do you think?  :)

 

by: andyclapPosted on 2000-08-23 at 16:08:51ID: 4045027

You could do a couple of things:

Draw the picture to the desktop hwnd. This is what vbmaster is proposing, but using a dragrectangle, not the picture. You'll need to think about refreshing what's underneath your image as you draw it, and it could be quite tricky to do to get the transparency right.

Use a picture box, and use the setwindowregion api commands to make it irregularly shaped. Unfortunately there's no createregion functions to create an irregular region from a mask or a transparent part of a gif, but if your image is a predictable shape, this would be straightforward. If your picture's transparency is unknown, you'll have to look into the picture's data and change the region pixel by pixel, which would probably be slow and as much work as drawing to the desktop hwnd.

 

by: amebaPosted on 2000-08-23 at 16:12:01ID: 4045051

'Here is the code with only one picturebox picTemp:

' add two Pictureboxes Picture1 and Picture2 (containers)
' add picturebox picTemp
' add Image control array: Image1(0) and Image1(1)...
'    put images into Picture1, set their icons
Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Type POINTAPI
    X As Long
    Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Dim startx As Single, starty As Single
Dim moving As Boolean
Dim movImage As Image

Private Sub Form_Load()
    Dim i As Long
    For i = Image1.LBound To Image1.UBound
        If Image1(i).Picture.Height = 0 Then
            Set Image1(i).Picture = Me.Icon
        End If
    Next
    picTemp.BorderStyle = 0
    picTemp.Visible = False
End Sub

Private Sub Image1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim ptTemp As POINTAPI
    If Button = vbLeftButton Then
        startx = X
        starty = Y
         
        GetCursorPos ptTemp
       
        ' remember which image it was, we'll need it later
        Set movImage = Image1(Index)
        ' hide image
        movImage.Visible = False
       
        picTemp.Visible = False
        Set picTemp.Picture = movImage.Picture
        picTemp.Move movImage.Left, movImage.Top, movImage.Width, movImage.Height
        SetParent picTemp.hwnd, 0&
        picTemp.Move ptTemp.X * 15 - startx, ptTemp.Y * 15 - starty
        picTemp.ZOrder 0
        picTemp.Visible = True
         
        SetCapture picTemp.hwnd
        moving = True
    End If
End Sub

Private Sub picTemp_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim ptTemp As POINTAPI
    If moving And Button = vbLeftButton Then
        GetCursorPos ptTemp
        picTemp.Move ptTemp.X * 15 - startx, ptTemp.Y * 15 - starty
    End If
End Sub

Private Sub picTemp_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim ptTemp As POINTAPI
    If moving And Button = vbLeftButton Then
        moving = False
        ReleaseCapture
         
        GetCursorPos ptTemp
         
        picTemp.Visible = False
         
        Dim NewContainer As Object ' form or control
        Dim HwndNewContainer As Long
        Dim ptNewContainer As POINTAPI
        HwndNewContainer = WindowFromPoint(ptTemp.X, ptTemp.Y)
         
        ' get new container
        If HwndNewContainer = Picture1.hwnd Then
            Set NewContainer = Picture1
        ElseIf HwndNewContainer = Picture2.hwnd Then
            Set NewContainer = Picture2
        ElseIf HwndNewContainer = Me.hwnd Then
            Set NewContainer = Me
        Else
            Set NewContainer = Me
            Beep
        End If

        Set movImage.Container = NewContainer
        ScreenToClient NewContainer.hwnd, ptTemp
        movImage.Move ptTemp.X * 15 - startx, ptTemp.Y * 15 - starty
        movImage.Visible = True
    End If
End Sub

 

by: amebaPosted on 2000-08-23 at 16:18:22ID: 4045086

>        movImage.Visible = True
>    End If
>End Sub

You can also add 2 lines:

        movImage.Visible = True
        movImage.ZOrder 0
        Set movImage = Nothing ' cleanup
    End If
End Sub

or make the picturebox picTemp transparent.

 

by: andyclapPosted on 2000-08-23 at 16:20:16ID: 4045089

If you are targetting Win2K only, there's a whole new ball-game of transparent (and alpha-channeled) windows.
But of course, nobody just targets Win2K...


Have you though about not using windowed controls at all on your form, ie getting rid of your picture box containers, just drawing them using shape controls (or GDI API)?

 

by: motilePosted on 2000-08-24 at 08:22:46ID: 4053715

Friends,
I realize now that there is no easy way of dealing with transparency while dragging over containers.

andyclap, the shapes of the images are not predictable and going pixel by pixel is not realistic at this stage. I thought about giving up on the containers, but I need them for scrolling, tabbing (TabStrip) and stuff like that, and not using containers will cause me much more headache than dragging the pictures.

ameba, I'm accepting your answer, although the transparency matter is not solved.

You are all so kind and helping, I wish I could give points to all of you.

And one more thing...
I'm not familiar with DirectX processing, but I think there is a way to define different levels of screens (like layers). If so, it could be the solution. Do you know anything about it?

 

by: amebaPosted on 2000-08-24 at 08:58:10ID: 4054329

Thanks for the points.

I have seen expert Mirkwood answered many questions about transparency. Maybe you can check some of his answers.
His profile:
http://www.experts-exchange.com/bin/ShowUser?login=Mirkwood

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...