473,386 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

dragdrop UserControl

Hi:

I have a form with a picture box and some command buttons to make
certain shapes appear in the picture box. The shapes are drawn on
blank UserControls added like this:

'at top of form module
Dim WithEvents tc As testControl

'button1_click (for example)
Set tc = Controls.Add("testproj.testControl", "tc[index]",
Form1.Picture1)

(then shapes are drawn on the control and it's added to a collection
of like shapes)
My idea was to have these UserControls store internally some data that
would enable them to interact, most importantly to implement dragdrop
operations so that one control dragged over a "hot spot" in another
control would site itself at that spot, after some validation.

Here's where I'm stuck: I've found example after example explaining
how to convert a point on one object to a point in its container, but
none of them have worked so far. I'm wondering if this is a result of
creating the UserControls at run-time? Specifically, here is what I
would like to happen, but can't pull it off:

When the shapes are drawn on the control, certain points are captured
as hot spots and stored in a read-only array. These coordinates remain
in the control's own scale and are not converted.

When one control is dropped onto another, the dragdrop event fires,
and I can confirm the source is at a point inside the target control.
I want to compare this point to the internally stored points of target
and select the closest hot point. Then I need to convert that hot
point to the picture1 coordinates and move the source control there.

This seems like it should be a piece of cake, but it's been driving me
crazy for almost a day now. Any help would be appreciated, thanks in
advance.
Jul 17 '05 #1
7 5822
On 9 Nov 2003 16:54:23 -0800, ka**@curio.com (Kate) wrote:
Hi:

I have a form with a picture box and some command buttons to make
certain shapes appear in the picture box. The shapes are drawn on
blank UserControls added like this:

'at top of form module
Dim WithEvents tc As testControl

'button1_click (for example)
Set tc = Controls.Add("testproj.testControl", "tc[index]",
Form1.Picture1)

(then shapes are drawn on the control and it's added to a collection
of like shapes)
My idea was to have these UserControls store internally some data that
would enable them to interact, most importantly to implement dragdrop
operations so that one control dragged over a "hot spot" in another
control would site itself at that spot, after some validation.

Here's where I'm stuck: I've found example after example explaining
how to convert a point on one object to a point in its container, but
none of them have worked so far. I'm wondering if this is a result of
creating the UserControls at run-time?
Definitely not - not a chance
Specifically, here is what I
would like to happen, but can't pull it off:

When the shapes are drawn on the control, certain points are captured
as hot spots and stored in a read-only array. These coordinates remain
in the control's own scale and are not converted. Ok, so you have an array of points in the ClientArea
When one control is dropped onto another, the dragdrop event fires,
and I can confirm the source is at a point inside the target control. because you have the X and Y coordinates ...I want to compare this point to the internally stored points of target
and select the closest hot point. Then I need to convert that hot
point to the picture1 coordinates and move the source control there. So you have points stored INSIDE a usercontrol, that you wish to
convert into points inside its parent - the Picturebox

Have you looked at the Extender properties of a Usercontrol ?

eg: UserControl.Extender.Left
This seems like it should be a piece of cake, but it's been driving me
crazy for almost a day now. Any help would be appreciated, thanks in
advance.

I'm not totally sure what you are up to ...

Another thing that could help is the ClientToScreen API
- and the ScreenToClient API
Jul 17 '05 #2
er*****@nowhere.com (J French) wrote in message news:<3f****************@news.btclick.com>...
On 9 Nov 2003 16:54:23 -0800, ka**@curio.com (Kate) wrote:
Here's where I'm stuck: I've found example after example explaining
how to convert a point on one object to a point in its container, but
none of them have worked so far. I'm wondering if this is a result of
creating the UserControls at run-time?


Definitely not - not a chance
Specifically, here is what I
would like to happen, but can't pull it off:

Have you looked at the Extender properties of a Usercontrol ?
eg: UserControl.Extender.Left

A bit..I know I want most of the code eventually inside the
UserControl module, but an early roadblock was that I cannot get the
dragdrop event inside the UserControl to fire--only the dragdrop event
of the run-time instance (and isn't it the Extender that provides
this...?) And as long as I'm stuck for the moment using the available
event, I want to at least figure out how to position a control where I
want it inside the picture control:

//pt is a POINTAPI, initially contains one of the hotspots inside
UserControl tc
pt.X = ScaleX(pt.X, vbTwips, vbPixels)
pt.Y = ScaleY(pt.Y, vbTwips, vbPixels)

//get the screen position of this point
ClientToScreen tc.GetHWnd, pt

//move the dragdrop source to the desired point on the target
Source.Move pt.X * Screen.TwipsPerPixelX - Picture1.Left, pt.Y * _
Screen.TwipsPerPixelY - Picture1.Top

Source just disappears, somewhere outside the picture box boundaries.
Jul 17 '05 #3
On 10 Nov 2003 06:26:48 -0800, ka**@curio.com (Kate) wrote:

<snip>
Have you looked at the Extender properties of a Usercontrol ?
eg: UserControl.Extender.LeftA bit..I know I want most of the code eventually inside the
UserControl module, but an early roadblock was that I cannot get the
dragdrop event inside the UserControl to fire--only the dragdrop event
of the run-time instance

I do not understand
- what is a run-time instance ?
.... you cannot have tried to 'fake' the recipient of an event (?)(and isn't it the Extender that provides
this...?) No, the Extender knows about its environment
- that is subtly different from what I think you are talking about And as long as I'm stuck for the moment using the available
event, I want to at least figure out how to position a control where I
want it inside the picture control:

//pt is a POINTAPI, initially contains one of the hotspots inside
UserControl tc
pt.X = ScaleX(pt.X, vbTwips, vbPixels)
pt.Y = ScaleY(pt.Y, vbTwips, vbPixels)

//get the screen position of this point
ClientToScreen tc.GetHWnd, pt

//move the dragdrop source to the desired point on the target
Source.Move pt.X * Screen.TwipsPerPixelX - Picture1.Left, pt.Y * _
Screen.TwipsPerPixelY - Picture1.Top

Source just disappears, somewhere outside the picture box boundaries.


Probably because it is way outside the boundaries

Why not just trace where it is ?
Jul 17 '05 #4
er*****@nowhere.com (J French) wrote in message news:<3f****************@news.btclick.com>...
On 10 Nov 2003 06:26:48 -0800, ka**@curio.com (Kate) wrote:

<snip>
Have you looked at the Extender properties of a Usercontrol ?
eg: UserControl.Extender.Left

A bit..I know I want most of the code eventually inside the
UserControl module, but an early roadblock was that I cannot get the
dragdrop event inside the UserControl to fire--only the dragdrop event
of the run-time instance

I do not understand
- what is a run-time instance ?
... you cannot have tried to 'fake' the recipient of an event (?)

Well, it's like this. I was working through the tutorial on creating
activeX control and want to see if control will support what I want to
do (create blank controls at runtime, draw on them as user dictates,
and allow user to site controls by dragging and dropping them). So I
have a control project and a test project to work with the control.

In the test project, events like click, mousedown, mouseup don't
appear in the pull-down procedure list unless I raise them in the
control project, but dragdrop appears automatically, and this is the
only dragdrop event that responds to my code (e.g., I deleted all
dragdrop code in the test project and put msgbox in control project
dragdrop--nothing happens when I drop onto an instance of my control
in this case. If I put the msgbox back into test project dragdrop, I
get the message.)

(and isn't it the Extender that provides
this...?)

No, the Extender knows about its environment
- that is subtly different from what I think you are talking about

Just received my book on COM/ActiveX, maybe that will clear things up.
Thanks--
Jul 17 '05 #5

"Kate" <ka**@curio.com> wrote in message
news:2c**************************@posting.google.c om...
er*****@nowhere.com (J French) wrote in message

news:<3f****************@news.btclick.com>...
On 10 Nov 2003 06:26:48 -0800, ka**@curio.com (Kate) wrote:

<snip>


In the test project, events like click, mousedown, mouseup don't
appear in the pull-down procedure list unless I raise them in the
control project, but dragdrop appears automatically, and this is the
only dragdrop event that responds to my code (e.g., I deleted all
dragdrop code in the test project and put msgbox in control project
dragdrop--nothing happens when I drop onto an instance of my control
in this case. If I put the msgbox back into test project dragdrop, I
get the message.)

I found the same result. The DragDrop event does not seem to fire inside the
UserControl code module - presumably it is preset to just raise the event
instead. However, the OleDragDrop event will fire there. If you change your test
project to use the Ole DragDrop events instead, you can probably make it work.
Jul 17 '05 #6

"Kate" <ka**@curio.com> wrote in message
news:2c**************************@posting.google.c om...
er*****@nowhere.com (J French) wrote in message

news:<3f****************@news.btclick.com>...
On 9 Nov 2003 16:54:23 -0800, ka**@curio.com (Kate) wrote:


//pt is a POINTAPI, initially contains one of the hotspots inside
UserControl tc
pt.X = ScaleX(pt.X, vbTwips, vbPixels)
pt.Y = ScaleY(pt.Y, vbTwips, vbPixels)

//get the screen position of this point
ClientToScreen tc.GetHWnd, pt

//move the dragdrop source to the desired point on the target
Source.Move pt.X * Screen.TwipsPerPixelX - Picture1.Left, pt.Y * _
Screen.TwipsPerPixelY - Picture1.Top


I think you should try
Source.Move pt.X, pt.Y

without any scaling. You are 1) converting X to pixels, 2) converting it to
screen position, 3) converting pixels back to Twips, and 4) offsetting that
amount not from the left edge of the screen, but from the left edge of Picture1.
You could similarly convert Picture1.Left to screen twips, and then offset from
that instead, but I think all the conversions cancel each other. You wind up the
original Pt.X twips from Picture1.Left.

Jul 17 '05 #7
On 10 Nov 2003 10:43:39 -0800, ka**@curio.com (Kate) wrote:
er*****@nowhere.com (J French) wrote in message news:<3f****************@news.btclick.com>...
On 10 Nov 2003 06:26:48 -0800, ka**@curio.com (Kate) wrote:
<snip>In the test project, events like click, mousedown, mouseup don't
appear in the pull-down procedure list unless I raise them in the
control project, but dragdrop appears automatically, and this is the
only dragdrop event that responds to my code (e.g., I deleted all
dragdrop code in the test project and put msgbox in control project
dragdrop--nothing happens when I drop onto an instance of my control
in this case. If I put the msgbox back into test project dragdrop, I
get the message.)


Here is an alternative :-

Option Explicit

' Add a Textbox
' Move Form or Textbox on MouseDown & Drag

Private Declare Function ReleaseCapture _
Lib "user32" () As Long
Private Declare Function SendMessage _
Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Any) As Integer
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2

Public Sub MoveObject(hwnd As Long)
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub

Private Sub Form_MouseDown(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
MoveObject Me.hwnd
End Sub
Private Sub Text1_MouseDown(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
MoveObject Text1.hwnd
End Sub

Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: KS | last post by:
I have a Button I want to pull to a Label. I want the Button visualy to move when I pull it. When I drop the button on the Label I want to test some data coming with the Button - f.ex is the...
1
by: KS | last post by:
In want to visualy drag a Button to a Label and when I depress the mousebutton on top of the label I want to show some dato from the Button in a MsgBox - that's my primary goal. I have made a...
2
by: dave | last post by:
I am wishing to drag something from the desktop to a tab of a tab control in vb.net. The dragdrop event fires when release the mouse above the tab however i am having a hard time trying to figure...
0
by: Flack | last post by:
Hello, Is it possible to find out how many methods are listening to a certain event? For example, if a number of methods subscribed to a controls DragDrop event using +=, can I find out how many...
0
by: SamSpade | last post by:
How to program DragDrop with a RichTextBox? If I develop by inherit I can override the DragDrop methods and do it that way. But if I want to include a RichTextBox on a UserControl the...
0
by: Gene Hubert | last post by:
Well, it seems fundamental to me anyway. Hopefully it is simple enough. The question is for when the source for the dragdrop is a different application that the target for the dragdrop. How...
3
by: Gary Dunne | last post by:
I'm writing an app that requires drag and drop operation between a ListView and a TreeView control. (The source is the ListView). During the drag drop operation I want to be able to detect the...
7
by: JohnR | last post by:
I am using dragdrop to drag and drop a custom class instance. When I drag/drop from one window to another window in the same application everything works fine. But when trying to move between the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.