返回列表 上一主題 發帖

[發問] 如何得知 Data.GetText 的來源是來自 listbox1 或 ,listbox2?

[發問] 如何得知 Data.GetText 的來源是來自 listbox1 或 ,listbox2?

又卡住了!請先進大大們協助
問題在同一userform1內含listbox1,listbox2,listbox3
其中 listbox1將資料拖曳給Comd1(欲限制其他Comd無法接受)
         listbox2將資料拖曳給Comd2~Comd5(欲限制其他Comd無法接受)等等
我使用如下  利用class1
Option Explicit
Dim newcontrol() As New Class1
Private Sub UserForm_Initialize()
     ReDim newcontrol(26)
    For i = 0 To 25
        Set newcontrol(i).Comd = Controls("CommandButton" & i + 1)
        newcontrol(i).Comd.Caption = ""
    Next
    listupdate1
    listupdate3
End Sub

Private Sub ListBox1_MouseMove(ByVal Button As  Integer, ByVal Shift As Integer, ByVal X As   Single, ByVal Y As Single)
    Dim MyDataObject As DataObject
    On Error Resume Next
    If Button = 1 Then
        Set MyDataObject = New DataObject
        Dim Effect As Integer
        MyDataObject.SetText ListBox1.Value
        Effect = MyDataObject.StartDrag
    End If
    On Error GoTo 0
End Sub
Private Sub ListBox3_MouseMove(ByVal Button As  Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Dim MyDataObject As DataObject
    On Error Resume Next
    If Button = 1 Then
        Set MyDataObject = New DataObject
        Dim Effect As Integer
        MyDataObject.SetText ListBox3.Value
        Effect = MyDataObject.StartDrag
    End If
    On Error GoTo 0
End Sub
class1
Private Sub Comd_BeforeDragOver(ByVal Cancel As  MSForms.ReturnBoolean, ByVal Data As  MSForms.DataObject, ByVal X As Single, _
    ByVal Y As Single, ByVal DragState As Long, ByVal Effect As MSF  orms.ReturnEffect,  ByVal Shift As Integer)
    Cancel = True
    Effect = 1
End Sub
Private Sub Comd_BeforeDropOrPaste(ByVal  Cancel As MSForms.ReturnBoolean, ByVal Action As Long, ByVal Data As  MSForms.DataObject, ByVal X As Single, _
    ByVal Y As Single, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
    Dim am%, row1%, mod1%, n1%, i%
    Dim n%
    Dim str1 As String
    Dim ss1%, ss2%, ss3%
    Dim ss4 As Variant
    Cancel = True
    Effect = 1
    am = Len(Comd.Name)
        If am = 14 Then
            str1 = Right(Comd.Name, 1)
        ElseIf am = 15 Then
            str1 = Right(Comd.Name, 2)
        End If
        n = CInt(str1)
    If n = 1 Then Comd.Caption = Data.GetText

就教於各位大大
        如何得知  Data.GetText 的來源是來自  listbox1   或    ,listbox2?

回復 2# luhpro
謝謝
個人想到一個方法是可以解決
用public flag as string
於  sub ListBox1_MouseMove內
下  flag="ListBox1"
於  sub ListBox2_MouseMove內
下  flag="ListBox2"   
於
Private Sub TextBox1_BeforeDropOrPaste(ByVal Cancel As MSForms.ReturnBoolean, ByVal Action As MSForms.fmAction, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
    Cancel = True
    Effect = 1
    If flag = "listbox1" Then TextBox1.Text = Data.GetText
'指定來源  才可 觸發   Data.GetText 之 paste動作
End Sub

TOP

回復 4# luhpro
謝謝
MouseMove 是因為 需要拖曳動作,
這次個人是使用  sub listbox1_Click()
          flag="listbox1" 如此一來,只要拖曳動作有則識別旗flag就舉旗

TOP

        靜思自在 : 脾氣嘴巴不好,心地再好也不能算是好人。
返回列表 上一主題