Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Ellipse Me.hdc, X1, Y1, X, Y
Me.Refresh '你漏了这句。当AutoRedraw为真时,必须调用此函数。
End Sub
Ellipse Me.hdc, X1, Y1, X, Y
Me.Refresh '你漏了这句。当AutoRedraw为真时,必须调用此函数。
End Sub
Option Explicit
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim flag As Boolean
Dim hdc1 As Long
Dim pos As RECT
Dim handle As Long
Dim X1 As Long
Dim x2 As Long
Dim y2 As Long
Dim Y1 As LongPrivate Sub Form_Load()
flag = False
Me.ScaleMode = 3
Me.AutoRedraw = False
hdc1 = GetDC(handle)
End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
flag = True
pos.Left = X
pos.Top = Y
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (flag) Then
pos.Right = X
pos.Bottom = Y
End If
End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (flag) Then
pos.Right = X
pos.Bottom = Y
Rectangle Me.hdc, pos.Left, pos.Bottom, pos.Right, pos.Top
flag = False
End If
End Sub
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim flag As Boolean
Dim pos As RECT
Private Sub Form_Load()
flag = False
Me.ScaleMode = 3
Me.AutoRedraw = False
End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
flag = True
pos.Left = X
pos.Top = Y
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (flag) Then
pos.Right = X
pos.Bottom = Y
End If
End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (flag) Then
pos.Right = X
pos.Bottom = Y
Me.ForeColor = vbRed
Ellipse Me.hdc, pos.Left, pos.Bottom, pos.Right, pos.Top
flag = False
End If
End Sub
Dim flag As Boolean
Dim hdc1 As Long
Dim handle As Long
Dim X1 As Long
Dim x2 As Long
Dim y2 As Long
Dim Y1 As LongPrivate Sub Form_Load()
flag = True
' Me.AutoRedraw = True 去掉该句
Me.ScaleMode = 3
Me.DrawWidth = 1
End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
X1 = X
Y1 = Y
End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Ellipse Me.hdc, X1, Y1, X, Y
End Sub
Dim flag As Boolean
Dim X1 As Long
Dim Y1 As LongPrivate Sub Form_Load()
flag = True
Me.ScaleMode = 3
Me.DrawWidth = 1
End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
X1 = X
Y1 = Y
End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Ellipse Me.hdc, X1, Y1, X, Y
End Sub