By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,760 Members | 1,585 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,760 IT Pros & Developers. It's quick & easy.

dragdrop UserControl

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.