Problem on dragging

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2009
Posts: 47
Reputation: Nada_ward is an unknown quantity at this point 
Solved Threads: 0
Nada_ward Nada_ward is offline Offline
Light Poster

Problem on dragging

 
0
  #1
Aug 1st, 2009
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 :

  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: Problem on dragging

 
0
  #2
Aug 1st, 2009
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 :)
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 47
Reputation: Nada_ward is an unknown quantity at this point 
Solved Threads: 0
Nada_ward Nada_ward is offline Offline
Light Poster

Re: Problem on dragging

 
0
  #3
Aug 1st, 2009
Teme64
thanks..

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

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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC