为了方便用户从列表或其它控件中(存有数据的控件)随意地获取数据,这在未来会很流行。
14 个解决方案
#1
用ole drag and drop
#2
建议你阅读一下MSDN里关于OLE拖放的段落。
#3
关注
#4
帮顶
#5
OLE
#6
创建一个ODL文件声明IDropSource、IDataObject和IDropTarget接口,编译成TLB后,在VB里实现OLE拖放。
#7
ole拖放
#8
试了,都不行,不是想要的那种,有没有谁提供源代码,加高分。
要求:1、选中列表框中一条记录;
2、拖动该记录至文本或一个按钮上时,则文本框中的内容或按钮的caption为该记录的内容;
要求:1、选中列表框中一条记录;
2、拖动该记录至文本或一个按钮上时,则文本框中的内容或按钮的caption为该记录的内容;
#9
关注
#10
天狼工作室
http://www.j2soft.cn/
源码如下:
源码如下:
Option Explicit
'在窗口左侧加一个ListBox控件,在窗口右侧加一个TextBox控件,并且将MultiLine属性设置为True
Private Sub Form_Load()
List1.OLEDragMode = 1
Text1.OLEDropMode = 1
List1.AddItem "aaa"
List1.AddItem "bbb"
List1.AddItem "ccc"
List1.AddItem "ddd"
List1.AddItem "eee"
End Sub
Private Sub List1_OLEStartDrag(Data As DataObject, AllowedEffects As Long)
AllowedEffects = vbDropEffectMove
End Sub
Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Text = Text1.Text & vbCrLf & List1.List(List1.ListIndex)
End Sub
#11
将Text的事件改成如下,可以在指定位置插件拖动的数据:
Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.SelText = List1.List(List1.ListIndex)
End Sub
#12
'注意:先选中,再拖动.
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const HWND_TOPMOST = -1
Const SWP_SHOWWINDOW = &H40
Private Declare Function SetWindowPos Lib _
"user32" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal X As Long, _
ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long
Private Sub Form_Load()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW
List1.OLEDragMode = 1
Text1.OLEDropMode = 1
For i = 0 To 19
List1.AddItem i & i
Next
End Sub
Private Sub List1_OLESetData(Data As DataObject, DataFormat As Integer)
If DataFormat = 1 Then '文本.txt格式
Data.SetData List1.Selected(List1.ListIndex)
End If
End Sub
Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
Effect = vbDropEffectCopy
Debug.Print Data.GetData(vbCFText)
If Data.GetFormat(vbCFText) Then
Text1.Text = Data.GetData(vbCFText)
End If
End Sub
#13
再次学习,多谢了!
#14
很实用的帖子!顶咯!
#1
用ole drag and drop
#2
建议你阅读一下MSDN里关于OLE拖放的段落。
#3
关注
#4
帮顶
#5
OLE
#6
创建一个ODL文件声明IDropSource、IDataObject和IDropTarget接口,编译成TLB后,在VB里实现OLE拖放。
#7
ole拖放
#8
试了,都不行,不是想要的那种,有没有谁提供源代码,加高分。
要求:1、选中列表框中一条记录;
2、拖动该记录至文本或一个按钮上时,则文本框中的内容或按钮的caption为该记录的内容;
要求:1、选中列表框中一条记录;
2、拖动该记录至文本或一个按钮上时,则文本框中的内容或按钮的caption为该记录的内容;
#9
关注
#10
天狼工作室
http://www.j2soft.cn/
源码如下:
源码如下:
Option Explicit
'在窗口左侧加一个ListBox控件,在窗口右侧加一个TextBox控件,并且将MultiLine属性设置为True
Private Sub Form_Load()
List1.OLEDragMode = 1
Text1.OLEDropMode = 1
List1.AddItem "aaa"
List1.AddItem "bbb"
List1.AddItem "ccc"
List1.AddItem "ddd"
List1.AddItem "eee"
End Sub
Private Sub List1_OLEStartDrag(Data As DataObject, AllowedEffects As Long)
AllowedEffects = vbDropEffectMove
End Sub
Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Text = Text1.Text & vbCrLf & List1.List(List1.ListIndex)
End Sub
#11
将Text的事件改成如下,可以在指定位置插件拖动的数据:
Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.SelText = List1.List(List1.ListIndex)
End Sub
#12
'注意:先选中,再拖动.
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const HWND_TOPMOST = -1
Const SWP_SHOWWINDOW = &H40
Private Declare Function SetWindowPos Lib _
"user32" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal X As Long, _
ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long
Private Sub Form_Load()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW
List1.OLEDragMode = 1
Text1.OLEDropMode = 1
For i = 0 To 19
List1.AddItem i & i
Next
End Sub
Private Sub List1_OLESetData(Data As DataObject, DataFormat As Integer)
If DataFormat = 1 Then '文本.txt格式
Data.SetData List1.Selected(List1.ListIndex)
End If
End Sub
Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
Effect = vbDropEffectCopy
Debug.Print Data.GetData(vbCFText)
If Data.GetFormat(vbCFText) Then
Text1.Text = Data.GetData(vbCFText)
End If
End Sub
#13
再次学习,多谢了!
#14
很实用的帖子!顶咯!