用VB实现拖放功能

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 vbfdy 的 blog

 

拖放是用鼠标拖动一个文件到其它对象的活动。在图形操作过程中,拖放是最常用的功能之一,下面我们来看看怎样用vb实现拖放功能。
  首先介绍与拖放有关的控件:
  1.属性:dragmode决定拖动操作的初始化是人工方式还是自动方式
      dragicon确定在拖动过程中显示的指针的图标形状
  2.方法:drag开始,结束或取消拖动控件
  3.事件:mousedown事件发生于用户按下鼠标按钮时。
       dragover事件发生于拖动操作完成时。
      dragdrop事件发生于拖动操作正在进行时。
  然后编写一个小程序,这个程序能实现在窗口中或窗口间拖动图标的功能。建
立窗口form1和form2,在窗口中都加入image1,其中form1下的image1.picture为你想显示的图标。
  form1下程序代码为:
  option explicit
  dim dragx as single
  dim dragy as single
  const begin_drag=1
  private sub form_dragdrop(source as control, x as single, y as single)
    image1.picture=source   ;sourse为被拖动的控件
  form2.image1.picture=loadpicture(″″)
  image1.move(x-dragx),(y-dragy); x,y为鼠标所在目标窗体或控件的当前坐标
  end sub
  private sub form_load()
   load form2
   form2.show 0
  end sub
  private sub image1_mousedown(button as integer,shift as integer,
x as single,y as single)
   dragx=x
   dragy=y
   image1.drag begin_drag   ;开始拖动操作
   image1.dragicon = loadpicture(″按下鼠标时想显示的光标″)
  end sub
   form2下程序代码为:
  option explicit
  dim dragx as single
  dim dragy as single
  const begin_drag=1
  private sub form_dragdrop(source as control,x as single,y as single)
   image1.picture=source
   form1.image1.picture=loadpicture(″″)
   image1.move(x-dragx),(y-dragy)
  end sub
  private sub image1_mousedown(button as integer, shift as integer,
x as single,y as single)
   dragx=x
   dragy=y
   image1.drag begin_drag
   image1.dragicon=loadpicture(″按下鼠标时想显示的光标″)
  end sub
  本程序在vb5.0,window95环境下通过

本文关键:拖放,VB
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top