我在picturebox里画矩形,并填充了它,我通过键盘vbKeyRight控制画,它一直往右画,然后用键盘vbKeyLeft,将光标至中间,然后用退格键删除,现在问题出来了,我删除了中间的,但是右边的要怎样紧跟光标向左覆盖过来呢?
代码如下,只需在桌面拖四个控件:Picture1,Line1,Timer1,Timer2
Private Sub Form_Load()
Timer1.Interval = 500
Timer2.Interval = 500
Line1.X1 = 0
Line1.X2 = 0
Line1.Y1 = 0
Line1.Y2 = Picture1.Height
Line1.BorderWidth = 4
Picture1.Move 240, 360, 6855, 1215
Line1.BorderColor = vbRed
End Sub
Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
Static x As Long
If KeyCode = vbKeyRight Then
x = x + 505
Picture1.AutoRedraw = True
If x Mod 2 = 0 Then
Picture1.Line (x, 0)-(x - 500, 1200), vbBlack, BF
Else
Picture1.Line (x, 0)-(x - 500, 1200), vbBlue, BF
End If
Line1.X1 = x
Line1.X2 = x
ElseIf KeyCode = vbKeyLeft Then
x = x - 505
Line1.X1 = x
Line1.X2 = x
ElseIf KeyCode = vbKeyBack Then
Picture1.Line (x, 0)-(x - 500, 1200), vbWhite, BF
x = x - 505
Line1.X1 = x
Line1.X2 = x
End If
End Sub
Private Sub Timer1_Timer()
Line1.Visible = True
End Sub
Private Sub Timer2_Timer()
Line1.Visible = False
End Sub