vb中画矩形的程序怎么写

 我来答
zgwxm
2012-05-12 · 经典歌曲、名人名家歌曲视频
zgwxm
采纳数:1792 获赞数:21142

向TA提问 私信TA
展开全部
不知道你想要什么样的画矩形的程序。下面是直接用鼠标在窗体上画矩形的。你只要按下鼠标左键在窗体上画,松开鼠标就会画出一个矩形来。
Dim CX0 As Long, CY0 As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
CX0 = X
CY0 = Y
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Me.Line (CX0, CY0)-(X, Y), , B
End If
End Sub
xljbear
2012-05-12 · TA获得超过145个赞
知道小有建树答主
回答量:175
采纳率:0%
帮助的人:176万
展开全部
以前写过一个比较复杂的
直接复制运行~
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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
xixiaohui002
2012-05-11 · TA获得超过1238个赞
知道小有建树答主
回答量:673
采纳率:50%
帮助的人:645万
展开全部
直接在form上作图的代码可以参考如下:
用一个的空白的form,上面放一个按钮,靠右边放,点击按钮将在form左上角画一个红矩形

Private Sub Command1_Click()
Me.DrawWidth = 2
Me.ForeColor = RGB(255, 0, 0)
Me.Line (200, 200)-(200, 500)
Me.Line (200, 500)-(500, 500)
Me.Line (500, 500)-(500, 200)
Me.Line (500, 200)-(200, 200)
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式