# 制作"选取方框"的疑惑

Posted by 笋子 on May 10, 1999 at 21:03:32:

我在做图形的"选取方框"时，却发现所框选出来的起始范围会相反耶...
他是以表单的"左上"到"右下"这一条线为主...程式码如下，请帮忙解惑...
谢谢，表单上只需有一个 Shape1 的物件....
Private Type CursorPosition
X As Single
Y As Single
End Type

Dim CursorStart As CursorPosition
Dim CursorEnd As CursorPosition

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Shape1.Width = 0: Shape1.Height = 0
CursorStart.X = X
CursorStart.Y = Y
Shape1.Top = X
Shape1.Left = Y
Shape1.Visible = True
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim CursorNow As CursorPosition
CursorNow.X = X
CursorNow.Y = Y
If Button Then
Shape1.Width = CursorNow.X - CursorStart.X
Shape1.Height = CursorNow.Y - CursorStart.Y
End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
CursorEnd.X = X
CursorEnd.Y = Y
Shape1.Height = CursorEnd.Y - CursorStart.Y
Shape1.Width = CursorEnd.X - CursorStart.X
End Sub

Follow Ups:

- 错一堆 小吴 09:54:36 5/11/99 (1)
  - 啊!!!真的是不好意思 笋子 11:36:10 5/11/99 (0)