请教:用鼠标左键在窗体上点击后拖动画出一个矩形,用vb怎么写?
展开全部
改了一下楼上的
Dim SX As Integer
Dim SY As Integer
Dim draw As Boolean
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
SX = X
SY = Y
draw = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If draw = True Then
Me.Cls
Line (SX, SY)-(X, Y), , B
Else
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
draw = False
Line (SX, SY)-(X, Y), , B
End Sub
Dim SX As Integer
Dim SY As Integer
Dim draw As Boolean
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
SX = X
SY = Y
draw = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If draw = True Then
Me.Cls
Line (SX, SY)-(X, Y), , B
Else
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
draw = False
Line (SX, SY)-(X, Y), , B
End Sub
追问
您好,要让画过的矩形保存在窗体上,该如何写?
追答
Dim SX As Integer
Dim SY As Integer
Dim draw As Boolean
Dim sp As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
SX = X
SY = Y
draw = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If draw = True Then
Me.Cls
Line (SX, SY)-(X, Y), , B
Else
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
draw = False
Line (SX, SY)-(X, Y), , B
b = "sp" & sp
Set a = Controls.Add("VB.Shape", b)
a.Visible = True
If X - SX <= 0 Then
a.Left = X
a.Width = Abs(X - SX)
Else
a.Left = SX
a.Width = X - SX
End If
If Y - SY <= 0 Then
a.Top = Y
a.Height = Abs(Y - SY)
Else
a.Top = SY
a.Height = Y - SY
End If
Me.Cls
sp = sp + 1
End Sub
嗯,这样就可以了!
-----美化版!空格键清屏~
Dim SX As Integer
Dim SY As Integer
Dim draw As Boolean
Dim sp As Long
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 32 Then
p = Me.Left
c = Me.Top
Unload Me
Me.Hide
Me.Left = p
Me.Top = c
Me.Show
End If
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
SX = X
SY = Y
draw = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If draw = True Then
Me.Cls
Line (SX, SY)-(X, Y), , B
Else
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
draw = False
Line (SX, SY)-(X, Y), , B
b = "sp" & sp
Set a = Controls.Add("VB.Shape", b)
a.Visible = True
If X - SX <= 0 Then
a.Left = X
a.Width = Abs(X - SX)
Else
a.Left = SX
a.Width = X - SX
End If
If Y - SY <= 0 Then
a.Top = Y
a.Height = Abs(Y - SY)
Else
a.Top = SY
a.Height = Y - SY
End If
Me.Cls
a.Shape = 4
a.BackStyle = 1
a.ZOrder
Randomize
a.BackColor = RGB(255 * Rnd(), 255 * Rnd(), 255 * Rnd())
sp = sp + 1
End Sub
展开全部
Dim SX As Integer
Dim SY As Integer
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
SX = X
SY = Y
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Line (SX, SY)-(X, Y), , B
End Sub
Dim SY As Integer
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
SX = X
SY = Y
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Line (SX, SY)-(X, Y), , B
End Sub
追问
您好,在拖动时能看见矩形,要怎么写?
追答
那要麻烦一些,今天没时间了。抽空给你写
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
spape 控件 vb 默认选项卡里 第一列 第九个
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询