473,587 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_MouseDo wn(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles Button1.MouseDo wn
If e.Button = MouseButtons.Le ft Then
Timer1.Enabled = True
GripOffset.X = e.X
GripOffset.Y = e.Y
Button1.DoDragD rop(Button1.Tag , DragDropEffects .Copy)
End If
End Sub
Private Sub label1_DragDrop (ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles Label1.DragDrop
If e.Data.GetData( DataFormats.Tex t).ToString = "SomeData" Then
Button1.Locatio n = PointToClient(M ousePosition)
Button1.BringTo Front()
MessageBox.Show ("Yes, it worked !")
Button1.Locatio n = New Point(15, 50)
End If
End Sub
Private Sub Label1_DragEnte r(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles Label1.DragEnte r
If e.Data.GetDataP resent(DataForm ats.Text) Then
e.Effect = DragDropEffects .Copy
End If
End Sub
Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
Dim NPos As New Point()
NPos = Me.PointToClien t(MousePosition )
NPos.Offset(-GripOffset.X, -GripOffset.Y)
Button1.Locatio n = 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.MouseEven tArgs) 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_MouseDo wn-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.Locati on =
PointToClient(M ousePosition)" - 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_MouseDo wn-event I actualy without any syntax error CAN write:

Button1.DoDragD rop(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 2516
KS
I found out myself !

KS, Denmark

"KS" <ke************ @os.dk> skrev i en meddelelse
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
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_MouseDo wn(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles Button1.MouseDo wn
If e.Button = MouseButtons.Le ft Then
Timer1.Enabled = True
GripOffset.X = e.X
GripOffset.Y = e.Y
Button1.DoDragD rop(Button1.Tag , DragDropEffects .Copy)
End If
End Sub
Private Sub label1_DragDrop (ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles Label1.DragDrop
If e.Data.GetData( DataFormats.Tex t).ToString = "SomeData" Then
Button1.Locatio n = PointToClient(M ousePosition)
Button1.BringTo Front()
MessageBox.Show ("Yes, it worked !")
Button1.Locatio n = New Point(15, 50)
End If
End Sub
Private Sub Label1_DragEnte r(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles Label1.DragEnte r
If e.Data.GetDataP resent(DataForm ats.Text) Then
e.Effect = DragDropEffects .Copy
End If
End Sub
Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
Dim NPos As New Point()
NPos = Me.PointToClien t(MousePosition )
NPos.Offset(-GripOffset.X, -GripOffset.Y)
Button1.Locatio n = 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.MouseEven tArgs) 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_MouseDo wn-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.Locati on =
PointToClient(M ousePosition)" - 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_MouseDo wn-event I actualy without any syntax error CAN write:
Button1.DoDragD rop(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
5836
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 module Dim WithEvents tc As testControl 'button1_click (for example)
0
1243
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 DragEnter/DragDrop events to handle Outlook objects? When Outlook objects are dropped on Explorer, a file is created with the subject as the name. I would like to recreate a similar behavior in MyApp.
0
1305
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 methods in total are listening to the DragDrop event of the control? If I can't find out the exact number of methods listening to the DragDrop event, can I somehow remove all listeners of that event at once? I tried using m_Control.DragDrop =...
0
1007
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 does the source for the dragdrop operation know that a drop has been completed onto a valid target? And then, how does the source know what the drop target is? I've got dragdrop working within my application but I can't see any
3
1846
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 textbox, the form the text box is on, and the parent form that opens the form the text box is on. I am using VB.NET 2002 with .NET Framework 1.0. How can I get the DragDrop event? TIA Bobbo
3
3780
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 target node in the treeview and auto expand it if applicable... but after a fair bit of head scratching I can't find any easy way to accomplish this. I think what i really need is the equivalent of the HitTest method from the COM version of the...
7
3989
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 same windows running in different instances of the application the "dropped" data comes across as a system.__ComObject and I can't CType it to my class to extract the data. I've been searching for hours and haven't found any solution so I am...
1
423
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 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.
0
7927
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8222
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5723
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3846
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2367
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1457
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1194
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.