Drag and drop function with VB

zhaozj2021-02-17  87

Drag and drop is an activity that is dragged a file to other objects with a mouse. Drag and drop is one of the most common functions during graphics operation. Let's take a look at how to use VB to implement drag and drop.

First introduce the controls related to drag and drop:

1. Properties: DragMode decides that the initialization of drag operation is manual way or automatic mode

Dragicon determines the icon shape of the pointer displayed during the drag

2. Method: DRAG starts, end or cancel the drag control

3. Event: MouseDown event occurs when the user presses the mouse button.

The Dragover event occurs when the drag operation is complete.

The DragDrop event occurs when the drag operation is in progress.

Then write a small program, which can be implemented in the window or the functionality of the icon between the window. build

Each window Form1 and Form2 add image1 in the window, where image1.picture under Form1 is the icon you want to display.

FORM1 down code is:

Option expedition

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 is dragged control

Form2.Image1.picture = loadingPicture ("")

Image1.move (x-Dragx), (Y-DRAGY); X, Y is the current coordinates of the target form or control of the mouse

End Sub

Private sub flow_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; start dragging operation

Image1.dragicon = loadingPicture ("Cursor wants to display when the mouse")

End Sub

FORM2 down code is:

Option expedition

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 = loadingPicture ("")

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 = loadingPicture ("Cursor wants to display when the mouse")

End Sub

This program passes the VB5.0, Window95 environment.

转载请注明原文地址:https://www.9cbs.com/read-29297.html

New Post(0)