热情软件屋

 

如何在同一个工程中进行拖放操作


编号:QA002807
建立日期: 2000年4月3日 最后修改日期:2000年4月3日
所属类别:

Dennis Wong:
    操作系统: Window 98, Window NT
    编程工具: Visual Basic 6.0
    问题: How to drag one Form's data to another Form in the same Project?
    I have a project contains 2 Forms. Both Forms have a listbox. And I want to drag Form 1's list1.text to Form2.list2.list. I know how to drag and drop within the same form, however, I don't know how to drag over one Form to another. Because the Mouse cannot receive window message when it leaves the Form. I have read some books which said that can done by API to catch the Mouse's position, such as GetCursorPos.. But I am just a beginner of VB, so I do not understand how to do it in real.

回答:

    实际上,在一个工程中进行拖放和在一个窗口内进行拖放并没有什么不同。下面是一个例子:
    1、建立一个工程,添加两个窗体:Form1和Form2。
    2、在两个Form上各放一个ListBox控件。
    3、设置Form1的List1的DragMode属性为自动。
    4、在Form1中输入代码:
    Private Sub Form_Load()
     Form2.Show
     List1.AddItem "test"
     List1.ListIndex = 0
    End Sub
    5、在Form2中输入如下代码:
    Private Sub List1_DragDrop(Source As Control, X As Single, Y As Single)
     List1.AddItem Source.Text
    End Sub
    6、运行程序,将Form1中的List1拖放到Form2的List1上。
    如果要在不同的工程中拖放,就需要使用OLEDragDrop等属性、事件和方法。
    
    相关问题:
    QA002536 "如何利用OLEDragDrop事件获得拖拽的文件名"
    QA002099 "从网页上拖URL到程序中是怎么实现的"

此问题由李海回答。

 
把这个问题推荐给朋友
   
   
您的意见类别
您的名字
您的电子邮件
您的建议(请尽可能详细)
 
 

版权所有 1997-2008 热情软件屋
如果您有任何建议和意见, 请给我发个电子邮件 askpro@china-askpro.com
Web Designed by ZebraStudio