VB   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了重拾VB6(20):Mouse Events, Drag and Drop大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

来自MSDN-2001-OCT: Visual Tools and Languages/Visual studio 6.0 Documentation/Visual Basic Documentation/Using Visual Basic/ProgrAMMer’s Guide/Part 2: what Can You Do With Visual Basic/Responding to Mouse and Keyboard Events/

1. Responding to Mouse Events

(1) You can use the MouseDown,MouseUp,and MouseMove events to enable your applications to respond to both the @R_675_5352@n and the state of the mouse.

(2) A form can recognize a mouse event when the pointer is over a part of the form where there are no controls. A control can recognize a mouse event when the pointer is over the control.

(3) When the user holds down a mouse button,the object conTinues to recognize all mouse events until the user releases the button. This is true even when the pointer is moved off the object.

(4) A bit-field argument returns information in individual bits,each inDicaTing whether a certain condition is on or off.

(5) Using binary notation,the three leftmost bits are referred to as @H_805_15@most-significant and the three rightmost bits as least-significant.

(6) Visual Basic doesn't necessarily generate a MouseMove event for every pixel the mouse moves over. The operaTing environment generates a limited number of mouse messages per second.

(7) Your application can recognize many MouseMove events in quick succession. Therefore,a MouseMove event procedure shouldn't do anything that requires large amounts of compuTing time.

2. DetecTing Mouse Buttons

(1)

(2) The button argument uses either a decimal value or an constant to represent these binary patterns.

Binary Value decimal Value Constant meaning
001 1 vbLeftButton The left button is pressed.
010 2 vbRightButton The right button is pressed.
100 4 vbMiddleButton The middle button is pressed.

(3) MouseDown and MouseUp only recognize one button press at a time.

(4) If the user presses more than one button,Visual Basic interprets that action as two or more separate MouseDown events. It sets the bit for the first button pressed,prints the message for that button,and then does the same for the next button.

(5) for the MouseMove event,button inDicates the complete state of the mouse buttons — not just which button caused the event,as with MouseDown and MouseUp. To test for whether a particular button is down,use the And operator.

Private Sub Form_MouseMove ( Button As Integer , _
Shift As Integer , X As Single , Y As Single)
If Button And 1 Then Print "You're pressing _
the left button."
If Button And 2 Then Print "You're pressing _
the right button."
End Sub

(6) The mouse and keyboard events use the shift argument to determine whether the SHIFT,CTRL,and ALT keys are pressed and in what,if any,combination. If the SHIFT key is pressed,shift is 1; if the CTRL key is pressed,shift is 2; and if the ALT key is pressed,shift is 4. To determine combinations of these keys,use the @R_514_10586@l of their values. For example,if SHIFT and ALT are pressed,shift equals 5 (1 + 4).

 

3. Dragging and Dropping

(1)

@H_675_224@Enables automatic or manual dragging of a control. @H_675_224@Specifies what icon is displayed when the control is dragged. @H_675_224@Recognizes when a control is dropped onto the object. @H_675_224@Recognizes when a control is dragged over the object. @H_681_220@methods @H_675_224@Starts or stops manual dragging.
Category Item Description
Properties DragMode
DragIcon
Events DragDrop
DragOver
Drag

(2) All controls except menus,timers,lines,and shapes support the DragMode and DragIcon properties and the Drag method. Forms recognize the DragDrop and DragOver events,but they don't support the DragMode and DragIcon properties or the Drag method.

(3) Controls can only be dragged when they do not have the focus. To prevent a control from getTing the focus,set its TabStop property to false.

4. Dragging and Dropping

(1) When you set dragging to Automatic (set its DragMode property to 1-AutomatiC),the control being dragged doesn't recognize other mouse events.

(2) When dragging a control,Visual Basic uses a gray outline of the control as the default drag icon. You can substitute other images for the outline by setTing the DragIcon property. This property contains a Picture object that corresponds to a graphic image.

(3) source: The control being dragged; Target: The object onto which the user drops the control.

(4) A control becomes the target if the mouse position is within its borders when the button is released. A form is the target if the pointer is in a blank portion of the form.

5. Controlling When Dragging Starts or Stops

(1) To enable dragging from code,leave DragMode in its default setTing (0-Manual). Then use the Drag method whenever you want to begin or stop dragging an object.

(2) The syntax for the Drag method is as follows:

[object.]Drag action

If action is set to vbBeginDrag,the Drag @H_849_6@method initiates dragging of the control. If action is set to vbEndDrag,the control is dropped,causing a DragDrop event. If action is set to vbCancel,the drag is canceled. The effect is SIMILAR TO giving the value vbEndDrag,except that no DragDrop event occurs.

6. Changing the Position of a Control

(1) You can reposition a control when it is dragged and dropped to any @R_675_5352@n on the form not occupied by another control.

(2) When the gray rectangle is being used,the user usually wants the control to move precisely into the final position of the gray rectangle. To do this,record the initial mouse position within the source control. Then use this position as an offset when the control is moved.

重拾VB6目录

大佬总结

以上是大佬教程为你收集整理的重拾VB6(20):Mouse Events, Drag and Drop全部内容,希望文章能够帮你解决重拾VB6(20):Mouse Events, Drag and Drop所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。