请教:用鼠标左键在窗体上点击后拖动画出一个矩形,用vb怎么写?

 我来答
xljbear
2011-06-27 · TA获得超过145个赞
知道小有建树答主
回答量:175
采纳率:0%
帮助的人:176万
展开全部
改了一下楼上的
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
mahu98
2011-06-27 · TA获得超过147个赞
知道小有建树答主
回答量:202
采纳率:0%
帮助的人:55万
展开全部
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
追问
您好,在拖动时能看见矩形,要怎么写?
追答
那要麻烦一些,今天没时间了。抽空给你写
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
12105412
2011-06-27 · TA获得超过817个赞
知道小有建树答主
回答量:1349
采纳率:0%
帮助的人:838万
展开全部
spape 控件 vb 默认选项卡里 第一列 第九个
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式