473,396 Members | 2,010 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,396 software developers and data experts.

Ones more - DragDrop in VB.NET 2002

KS
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 simple sample code - a form with a Button1, a Label1 and a
Timer1.

The Button1 has Tag="SomeData", the Label1 has AllowDrop=True and the Timer1
has an Interval=20.

Paste this code to your solution - from here:

Dim GripOffset As Point
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
If e.Button = MouseButtons.Left Then
Timer1.Enabled = True
GripOffset.X = e.X
GripOffset.Y = e.Y
Button1.DoDragDrop(Button1.Tag, DragDropEffects.Copy)
End If
End Sub
Private Sub label1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles Label1.DragDrop
If e.Data.GetData(DataFormats.Text).ToString = "SomeData" Then
Button1.Location = PointToClient(MousePosition)
Button1.BringToFront()
MessageBox.Show("Yes, it worked !")
Button1.Location = New Point(15, 50)
End If
End Sub
Private Sub Label1_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles Label1.DragEnter
If e.Data.GetDataPresent(DataFormats.Text) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim NPos As New Point()
NPos = Me.PointToClient(MousePosition)
NPos.Offset(-GripOffset.X, -GripOffset.Y)
Button1.Location = NPos
End Sub
' MouseUp never executes - why ?
' Is it disabled or by some other meens controled by the DoDragDrop in
MouseDown-event ?
Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
Timer1.Enabled = False
End Sub

' to here !!!!!!!!

Compiler and drag the Button1 to the Label1 - the Button is visualy
following the mouse but it wont drop at all - you have to right-click the
mouse and the usual 'DragDrop-system' with my MsgBox is NOT working.

Now - in the Button1_MouseDown-event comment out the Timer1.Enabled=True and
start again - now the 'DragDrop-system' with my MsgBox is IS working but the
Button1 is NOT visualy following the mouse but jumps to the Label1 when I
depress the mouseButton.

I think the latter solution works the best way so that you can comment out
all the Timer-related-code.

BUT in my application where I plan to use this 'DragDrop-functionality' I
can NOT reference the Button1 directly when I move it in the
Label1_DragDrop-event - that is - I can NOT use the "Button1.Location =
PointToClient(MousePosition)" - therefore:

How can I Drag and Drop an object as a whole unit (here a Button) so that I
in the Label1_DragDrop-event can work on that 'dropped object' and get
access to all it's properties etc. ?

In the Button1_MouseDown-event I actualy without any syntax error CAN write:

Button1.DoDragDrop(Button1, DragDropEffects.Copy) ' where 'the whole
object' Button1 is referenced !

But what shall I do in the DragEnter and DragDrop events to tell thats is
the whole object I want to work with ?

How can I do this ?

KS, Denmark
Jul 21 '05 #1
1 2493
KS
I found out myself !

KS, Denmark

"KS" <ke************@os.dk> skrev i en meddelelse
news:%2******************@TK2MSFTNGP11.phx.gbl...
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 simple sample code - a form with a Button1, a Label1 and a
Timer1.

The Button1 has Tag="SomeData", the Label1 has AllowDrop=True and the Timer1 has an Interval=20.

Paste this code to your solution - from here:

Dim GripOffset As Point
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
If e.Button = MouseButtons.Left Then
Timer1.Enabled = True
GripOffset.X = e.X
GripOffset.Y = e.Y
Button1.DoDragDrop(Button1.Tag, DragDropEffects.Copy)
End If
End Sub
Private Sub label1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles Label1.DragDrop
If e.Data.GetData(DataFormats.Text).ToString = "SomeData" Then
Button1.Location = PointToClient(MousePosition)
Button1.BringToFront()
MessageBox.Show("Yes, it worked !")
Button1.Location = New Point(15, 50)
End If
End Sub
Private Sub Label1_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles Label1.DragEnter
If e.Data.GetDataPresent(DataFormats.Text) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim NPos As New Point()
NPos = Me.PointToClient(MousePosition)
NPos.Offset(-GripOffset.X, -GripOffset.Y)
Button1.Location = NPos
End Sub
' MouseUp never executes - why ?
' Is it disabled or by some other meens controled by the DoDragDrop in
MouseDown-event ?
Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
Timer1.Enabled = False
End Sub

' to here !!!!!!!!

Compiler and drag the Button1 to the Label1 - the Button is visualy
following the mouse but it wont drop at all - you have to right-click the
mouse and the usual 'DragDrop-system' with my MsgBox is NOT working.

Now - in the Button1_MouseDown-event comment out the Timer1.Enabled=True and start again - now the 'DragDrop-system' with my MsgBox is IS working but the Button1 is NOT visualy following the mouse but jumps to the Label1 when I
depress the mouseButton.

I think the latter solution works the best way so that you can comment out
all the Timer-related-code.

BUT in my application where I plan to use this 'DragDrop-functionality' I
can NOT reference the Button1 directly when I move it in the
Label1_DragDrop-event - that is - I can NOT use the "Button1.Location =
PointToClient(MousePosition)" - therefore:

How can I Drag and Drop an object as a whole unit (here a Button) so that I in the Label1_DragDrop-event can work on that 'dropped object' and get
access to all it's properties etc. ?

In the Button1_MouseDown-event I actualy without any syntax error CAN write:
Button1.DoDragDrop(Button1, DragDropEffects.Copy) ' where 'the whole
object' Button1 is referenced !

But what shall I do in the DragEnter and DragDrop events to tell thats is
the whole object I want to work with ?

How can I do this ?

KS, Denmark

Jul 21 '05 #2

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

Similar topics

7
by: Kate | last post by:
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...
0
by: Eric St-Onge | last post by:
Hi, I need to dragdrop message items from Outlook (2002 and 2003) to my application. I successfully implemented DragDrop from Explorer to MyApp but I didnt find how to properly code...
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: 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: Robert S. Liles | last post by:
I am trying to drag a text file and drop it into a multiline text box. I get DragEnter, DragOver, and DragLeave events, but I don't get a DragDrop event. I have AllowDrop set to TRUE for the...
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...
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...
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.