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 :

dim l1 as label
Dim serverindex, serverP As Integer
    Dim serverref As String
    Dim copiedFragment As String
    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 l1=new label()
l1.text="string"
  AddHandler l1.MouseDown, AddressOf labelmouse_down
      AddHandler l1.MouseMove, AddressOf labelmove
 AddHandler Label11.DragEnter, AddressOf enter_server

    End Sub

Sub enter_server( _
                 ByVal sender As System.Object, _
                 ByVal e As System.Windows.Forms.DragEventArgs)
       

        Dim len As Integer = draggedlabel.IndexOf(":")
        draggedlabel = draggedlabel.Substring(0, len)
        serverP = serverindex
        serverref = sender.text

        
        If e.Data.GetDataPresent(DataFormats.Text) Then
            paste(len, draggedlabel, True)
            ' move variable 
            If MsgBox("Do yo want to move " & draggedlabel & _
         " from " & vbCrLf & server_names(serverP), MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                e.Effect = DragDropEffects.Copy
                paste(len, draggedlabel, True)
            Else
                e.Effect = DragDropEffects.Move
                paste(len, draggedlabel, False)
            End If
        Else
            e.Effect = DragDropEffects.None
        End If

end sub
 Sub labelmouse_down( _
                ByVal sender As System.Object, _
                ByVal e As System.Windows.Forms.MouseEventArgs)
        If (e.Button.Left) Then
            mouse = True
            ' MsgBox(sender.text)


        End If


    End Sub
Sub labelmove( _
              ByVal sender As System.Object, _
              ByVal e As System.Windows.Forms.MouseEventArgs)
        If mouse = True Then
            sender.DoDragDrop(sender.text, DragDropEffects.Copy Or DragDropEffects.Move)

        End If
        draggedlabel = sender.text
        ' RemoveHandler Label1.MouseUp, AddressOf mouse_up
        mouse = False
    End Sub
        

Sub paste(ByVal len As Integer, ByVal copied_fragment As String, ByVal cut As Boolean)
msgbox(len.tostring & copied_fragment )
    End Sub

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.