New topic: 

Super-simple drag and drop for a control on a window?

<http://forums.realsoftware.com/viewtopic.php?t=46618>

         Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic          Author  
Message        barrytraver          Post subject: Super-simple drag and drop 
for a control on a window?Posted: Sat Jan 19, 2013 7:18 am                      
   
Joined: Fri Sep 30, 2005 1:53 pm
Posts: 785
Location: Philadelphia, PA                What I want to do seems simple, but 
the instructions for using Drag and Drop do not seem at all simple to me.

Here's what I want to do:

(1) Put a control (e.g., say, a pushbutton or maybe a rectangle?) on a window.  
(That much I can do.)

(2) Do what I need to do so that I can pick up the control by putting the mouse 
cursor over it, hold down the left mouse button, and -- by moving the mouse 
cursor (with the control attached) -- move the control to someplace else on the 
window.  (That I can't figure out how to do.)

(3) Do what I need to do so that when the mouse button is released the control 
will stay where it is at the time of the release.  (That I also can't figure 
out how to do.)

I learn best from sample code, but the sample code I've found and tried thus 
far doesn't seem to work "as is."  It expects me to know enough already about 
programming to make the minor but necessary modifications required for the code 
to work.  I'm sure the fault is mine rather than the fault of the person who 
wrote the code, but that recognition and admission of my still being a "newby" 
after years of working with REALbasic doesn't get me closer to the goal, a goal 
that should be fairly reachable (even for me).

Now that I've renewed the Enterprise edition for two years, I hope to work my 
way through all the REALbasic documentation (including the Tutorial and User's 
Guide), but it may be a while before I or they get to "Drag and Drop," and I 
will have -- through reading the documentation starting at page 1 -- learned a 
lot of things in the meantime (e.g., database management) for which I have no 
immediate use.

I do have an immediate use for "Drag and Drop."  Is there no hope of my  
getting some super-simple source code which will work "as is" to illustrate the 
simplest situation?  (Often if I can just get started, I can move on from 
there.)

Thanks in advance for any help you may be able to provide.

Barry Traver   
                             Top                lenpartico          Post 
subject: Re: Super-simple drag and drop for a control on a window?Posted: Sat 
Jan 19, 2013 3:35 pm                         
Joined: Fri Sep 30, 2005 10:49 pm
Posts: 477                Did you check DragPics in the Example projects?
Example projects/Graphics/DragPics

Lennox   
                             Top                pixe656          Post subject: 
Re: Super-simple drag and drop for a control on a window?Posted: Sat Jan 19, 
2013 3:53 pm                         
Joined: Wed May 20, 2009 11:02 am
Posts: 401                Check this: 
http://forums.realsoftware.com/viewtopic.php?f=1&t=42036

Pixe      
_________________
Using RS2011r4.3 on Windows7.  
                             Top                timhare          Post subject: 
Re: Super-simple drag and drop for a control on a window?Posted: Sat Jan 19, 
2013 4:01 pm                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 11996
Location: Portland, OR  USA                Unfortunately, this is not a simple 
problem.  Or rather, most controls don't expose the events you need for the 
simple solution. It works well enough with a canvas, but not with very many 
other controls.  Also, this isn't really a "Drag and Drop" problem in the 
normal sense.

So it's not just you.

Here is the "simple" solution for a canvas:

Add a canvas on the window.  Add 2 properties to the window:
saveX as Integer
saveY as Integer


In the Canvas Paint event, draw something so you can see where to click:
g.ForeColor = &c0000FF
g.DrawRect(0,0,me.Width,me.Height)


In the Canvas MouseDown event, initiate a mouse drag:
saveX = MouseX  // use the values relative to the Window, not the control
saveY = MouseY
return True


In the Canvas MouseDrag event, move the control:
me.left = me.left + (MouseX - saveX)
me.top = me.top + (MouseY - saveY)
saveX = MouseX
saveY = MouseY


Run the project, click on the canvas and drag it around.  Note that this does 
not use any of the DragXXX events as you might expect, but rather relies on the 
MouseDrag event, which is only exposed in a few controls.  So this will not 
work on every control.

HTH,
Tim   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to