Solved

dragging a picturebox over another picturebox.

Posted on 2009-04-06
2
763 Views
Last Modified: 2013-11-26
Hi,

I am developing a VC++ application and I am trying to make a circle image over a map image to be draggable by mouse. I did this by first creating a picturebox which has its image set to a map and the circle as anothe picturebox  (PNG) which has transparency.

I am setting the first picturebox as the parent of the second picturebox.

I am making the image draggable by using the mousedown events and mouse move events to relocate the circle picturebox to the mouse pointer position.

The problem is, when I do this, the transparent areas of the circle image look messy (flickering) and the circle image is looking strange and not moving smoothly. Am I doing anything wrong? is there a better way to achieve this in VC++ dot net?

Regards,
0
Comment
Question by:gghaleb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
omegaomega earned 500 total points
ID: 24089507
Hello, gghaleb,

You might find this smoother if you don't bother with the second PictureBox but instead just draw the circle during the map PictureBox's Paint event.  The snippet shows a simple example.  (It's in VB, but you probably won't have any trouble converting it.)   The MouseMove and MouseUp events simply request repainting of the PictureBox.  The Paint event is then used to draw the circle.

Cheers,
Randy

Public Class Form1
 
    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If (e.Button = Windows.Forms.MouseButtons.Left) Then
            PictureBox1.Invalidate()
        End If
    End Sub
 
    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        PictureBox1.Invalidate()
    End Sub
 
    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        If (Control.MouseButtons = Windows.Forms.MouseButtons.Left) Then
            Const Radius As Integer = 30
            Dim Centre As Point = PictureBox1.PointToClient(Control.MousePosition)
            Dim CircleFrame As New Rectangle(Centre.X - Radius, Centre.Y - Radius, 2 * Radius, 2 * Radius)
            e.Graphics.DrawEllipse(Pens.Black, CircleFrame)
        End If
    End Sub
 
End Class

Open in new window

0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
API v SOA 8 63
Asp.Net Session Question 2 47
Make borderless form movable by user 2 26
unable to isntall .net framework 3.5 19 32
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question