943,733 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 385
  • VB.NET RSS
Aug 1st, 2009
0

Problem on dragging

Expand Post »
Hi
I have problem on dragging label
when the application show msgbox , it stop responding
I do n't know what is problem in my code :

vb .net Syntax (Toggle Plain Text)
  1. dim l1 as label
  2. Dim serverindex, serverP As Integer
  3. Dim serverref As String
  4. Dim copiedFragment As String
  5. Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6. l1=new label()
  7. l1.text="string"
  8. AddHandler l1.MouseDown, AddressOf labelmouse_down
  9. AddHandler l1.MouseMove, AddressOf labelmove
  10. AddHandler Label11.DragEnter, AddressOf enter_server
  11.  
  12. End Sub
  13.  
  14. Sub enter_server( _
  15. ByVal sender As System.Object, _
  16. ByVal e As System.Windows.Forms.DragEventArgs)
  17.  
  18.  
  19. Dim len As Integer = draggedlabel.IndexOf(":")
  20. draggedlabel = draggedlabel.Substring(0, len)
  21. serverP = serverindex
  22. serverref = sender.text
  23.  
  24.  
  25. If e.Data.GetDataPresent(DataFormats.Text) Then
  26. paste(len, draggedlabel, True)
  27. ' move variable
  28. If MsgBox("Do yo want to move " & draggedlabel & _
  29. " from " & vbCrLf & server_names(serverP), MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
  30. e.Effect = DragDropEffects.Copy
  31. paste(len, draggedlabel, True)
  32. Else
  33. e.Effect = DragDropEffects.Move
  34. paste(len, draggedlabel, False)
  35. End If
  36. Else
  37. e.Effect = DragDropEffects.None
  38. End If
  39.  
  40. end sub
  41. Sub labelmouse_down( _
  42. ByVal sender As System.Object, _
  43. ByVal e As System.Windows.Forms.MouseEventArgs)
  44. If (e.Button.Left) Then
  45. mouse = True
  46. ' MsgBox(sender.text)
  47.  
  48.  
  49. End If
  50.  
  51.  
  52. End Sub
  53. Sub labelmove( _
  54. ByVal sender As System.Object, _
  55. ByVal e As System.Windows.Forms.MouseEventArgs)
  56. If mouse = True Then
  57. sender.DoDragDrop(sender.text, DragDropEffects.Copy Or DragDropEffects.Move)
  58.  
  59. End If
  60. draggedlabel = sender.text
  61. ' RemoveHandler Label1.MouseUp, AddressOf mouse_up
  62. mouse = False
  63. End Sub
  64.  
  65.  
  66. Sub paste(ByVal len As Integer, ByVal copied_fragment As String, ByVal cut As Boolean)
  67. msgbox(len.tostring & copied_fragment )
  68. End Sub
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Nada_ward is offline Offline
53 posts
since Jul 2009
Aug 1st, 2009
0

Re: Problem on dragging

Here's a few things to fix first:

- add Option Strict On and Option Explicit On lines at the beginning of vb-file
- line 19: you refer to draggedlabel but you haven't declared it. Is it a label control in the form?
- line 22: sender is of type Object which does not have Text property and thus serverref = sender.text does not work. You have to cast sender to correct type first. If it's a label, use serverref = CType(sender, Label).Text
- line 44: should be If e.Button = Windows.Forms.MouseButtons.Left Then
- lines 57 and 60: cast sender object to correct type, like CType(sender, Label)

Simply fixing these type issues may solve your problem. I don't remember seeing an app that prompts a message box at DragEnter event but without actually testing it, I don't see any reason why it shouldn't work. In general I would personally take away that confirmation. If the user has an opportunity to drag&drop something, he/she usually knows what he/she is doing

HTH
Last edited by Teme64; Aug 1st, 2009 at 6:35 am. Reason: Pressed submit by mistake :)
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Teme64 is offline Offline
1,024 posts
since Aug 2008
Aug 1st, 2009
0

Re: Problem on dragging

Teme64
thanks..

Quote ...
line 19: you refer to draggedlabel but you haven't declared it. Is it a label control in the form?
I declare draggedlabel a0s string

Quote ...
serverref = sender.text does not work
ther I havn't broblem , this statment works

maebe your away to get text of label better , thanks

I removed msg boxes from dragEnterEvent , so , I put it in DragDrop event .
the dragged label must enter both event dragEnter and DragDrop ..

It's now work Properly
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Nada_ward is offline Offline
53 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Data updated Problem
Next Thread in VB.NET Forum Timeline: Call a button click event under another sub procedure





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC