vb中画矩形的程序怎么写
3个回答
展开全部
不知道你想要什么样的画矩形的程序。下面是直接用鼠标在窗体上画矩形的。你只要按下鼠标左键在窗体上画,松开鼠标就会画出一个矩形来。
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
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
展开全部
以前写过一个比较复杂的
直接复制运行~
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
直接在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
用一个的空白的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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询