다음을 통해 공유


Visual Basic 6.0 사용자를 위한 끌어서 놓기

업데이트: 2007년 11월

Visual Basic 2008의 끌어서 놓기 편집을 구현하는 모델은 Visual Basic 6.0 모델과 상당히 다릅니다.

개념적 차이

Visual Basic 6.0에서는 서로 다른 두 가지 방법으로 끌어서 놓기 편집을 수행할 수 있습니다. 첫 번째 방법은 폼에 있는 컨트롤 간에 적용되는 표준 끌기이고 두 번째 방법은 서로 다른 폼 및 응용 프로그램 간에 적용되는 OLE 끌기입니다.

Visual Basic 2008에서는 끌어서 놓기 편집에 단일 모델이 사용됩니다. 이 모델은 OLE 끌기와 유사하지만 끌어서 놓기 메서드 및 이벤트의 이름과 매개 변수가 다르고 이벤트 모델도 다릅니다.

끌어서 놓기에 대한 코드 변경 사항

텍스트를 끌어서 놓는 방법에 대한 변경 사항

다음 예제에서는 텍스트를 한 TextBox 컨트롤에서 다른 컨트롤로 끌기에 대한 코드의 차이점을 보여 줍니다.

' Visual Basic 6.0
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text1.Text = "Hello World"
    ' Begin dragging by calling the OLEDrag method.
    Text1.OLEDrag
End Sub

Private Sub Text1_OLEStartDrag(Data As DataObject, AllowedEffects As Long)
    ' Only allow copying.
    AllowedEffects = vbDropEffectCopy
    Data.Clear
    ' Populate the Data object with the text to copy and the format.
    Data.SetData Text1.Text, vbCFText
End Sub

Private Sub Text2_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
    ' Make sure that the format is text.
    If Data.GetFormat(vbCFText) Then
      ' If it is text, enable dropping for the second TextBox.
      Text2.OLEDropMode = vbOLEDropManual
    End If
End Sub

Private Sub Text2_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    ' Copy the text from the Data object to the second TextBox.
    Text2.Text = Data.GetData(vbCFText)
End Sub
' Visual Basic
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e _
As System.EventArgs) Handles MyBase.Load

    ' Dropping must be enabled before the dragging occurs.
    TextBox2.AllowDrop = True
End Sub

Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown

    TextBox1.Text = "Hello World"
    ' Begin dragging by calling the DoDragDrop method.
    ' OLEStartDrag is replaced by arguments on the method.
    TextBox1.DoDragDrop(TextBox1.Text, DragDropEffects.Copy)
End Sub

Private Sub TextBox2_DragEnter(ByVal sender As Object, ByVal e _
As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter

    ' Make sure that the format is text.
    If (e.Data.GetDataPresent(DataFormats.Text)) Then
      ' Allow drop.
      e.Effect = DragDropEffects.Copy
    Else
      ' Do not allow drop.
      e.Effect = DragDropEffects.None
    End If
End Sub

Private Sub TextBox2_DragDrop(ByVal sender As Object, ByVal e _
As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop

    ' Copy the text to the second TextBox.
    TextBox2.Text = e.Data.GetData(DataFormats.Text).ToString
End Sub

업그레이드 참고 사항

끌어서 놓기 코드는 자동으로 Visual Basic 2008로 업그레이드할 수 없으므로 새 모델을 사용하여 다시 작성해야 합니다. 끌어서 놓기 코드는 업그레이드 프로세스 동안 업그레이드 경고로 표시됩니다.

참고 항목

기타 리소스

끌어서 놓기 작업 및 클립보드 지원