Drag and drop problem

S

Steve

Hi All

I have a windows forms vb.net 2005 application

I have a form with buttons representing restaurant tables

To allow the user to join Tables at certain times I use drag and drop
When the user drags a button on to another, the one being dragged is made
invisible and the one dropped on to gets wider and has the seating capacity
increased

When loading the form the tables are created in code from left to right,
then next row from left to right
e.g 1 2 3 4 etc

All works well when dragging from higher number table to lower table (i.e
from right to left). The join works great
When I drag a lower number table to a higher number table the dragdrop event
doesn't fire

I have noticed when dragging from right to left, the dragged button passes
behind the button being dropped on whereas dragging left to right the
dragged button passes over the button being dropped on

Maybe it is a z-order issue I am not sure

Any help appreciated

Regards
Steve

code to load buttons.............
btn = New Button

btn.Name = CStr(dr("pbname"))

btn.Tag = dr

If Not dr("joined") OrElse dr("joinmaster") Then

btn.Visible = True

Else

btn.Visible = False

End If

btn.Left = CInt(dr("pbleft"))

btn.Top = CInt(dr("pbtop"))

If Not IsDBNull(dr("pbheight")) Then

btn.Height = CInt(dr("pbheight"))

End If

If Not IsDBNull(dr("pbwidth")) Then

btn.Width = CInt(dr("pbwidth"))

End If

btn.Font = New Font(btn.Font.FontFamily, btn.Font.Size, FontStyle.Bold)

btn.AllowDrop = True

btn.AllowFocus = False

btn.BringToFront()

AddHandler btn.MouseDown, AddressOf btn_Mousedown

AddHandler btn.MouseUp, AddressOf btn_mouseUp

AddHandler btn.MouseMove, AddressOf btn_MouseMove

AddHandler btn.MouseEnter, AddressOf btn_MouseEnter

AddHandler btn.MouseLeave, AddressOf btn_MouseLeave

AddHandler btn.Click, AddressOf btn_click

AddHandler btn.DragDrop, AddressOf btn_DragDrop

AddHandler btn.DragEnter, AddressOf btnDragEnter

pnlTables.Controls.Add(btn)
 
L

Linda Liu[MSFT]

Hi Steve,

I performed a test based on your description but didn't reproduce the
problem on my side.

In my test, I create a WinForm application project and add two Buttons on
the form. The code in the form is as follows:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Button2.AllowDrop = True
Button1.AllowDrop = True
AddHandler Me.Button1.MouseMove, AddressOf ButtonMouseMove
AddHandler Me.Button1.DragEnter, AddressOf ButtonDragEnter
AddHandler Me.Button1.DragDrop, AddressOf ButtonDragDrop

AddHandler Me.Button2.MouseMove, AddressOf ButtonMouseMove
AddHandler Me.Button2.DragEnter, AddressOf ButtonDragEnter
AddHandler Me.Button2.DragDrop, AddressOf ButtonDragDrop
End Sub

Sub ButtonDragDrop(ByVal sender As Object, ByVal e As DragEventArgs)
Dim draggedbtn As Button = CType(e.Data.GetData(GetType(Button)),
Button)
Dim dropbtn As Button = CType(sender, Button)
dropbtn.Text += vbNewLine + draggedbtn.Name
Me.Controls.Remove(draggedbtn)
End Sub

Sub ButtonDragEnter(ByVal sender As Object, ByVal e As DragEventArgs)
If (e.Data.GetDataPresent(GetType(Button))) Then
e.Effect = DragDropEffects.Move
End If
End Sub

Sub ButtonMouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim btn As Button = CType(sender, Button)
If (e.Button = Windows.Forms.MouseButtons.Left) Then
btn.DoDragDrop(btn, DragDropEffects.Move)
End If
End Sub
End Class

Build and run the application. Drag&drop Button1 onto Button2. You should
see Button1 disppears and the name of the Button1 is added to the Button2's
Text and vice versa.

Is there any difference between your code and mine?
If the problem is still not solved, you'd better reproduce the problem in a
simple project and send it to me. To get my actual email address, remove
'online' from my displayed email address.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steve

Hi Linda

Thanks for the reply

I tested your code and it definitely works fine

I will check my code to see where I have made a mistake

Regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top