先看看我的代码:
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
msngX = X
msngY = Y
End If
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
Picture1.Line (msngX, msngY)-(X, Y), , B
Picture1.DrawMode = vbNotXorPen
Picture1.Line (msngX, msngY)-(X, Y), , B
End If
End Sub
在PictureBox上用鼠标作图,要求效果就象在设计时用shape在picturebox上放一个矩形一样。上述代码当鼠标移动时,会出现一个随鼠标变化的矩形,只要在mouseup事件中,画出这个矩形就可以了。问题是,当鼠标停止移动时而又没有释放按纽时,矩形的外框看不见,原因是mousemove中,最后总是使drawmode=vbnotxorpen,所以停止不动时,看不见外框,怎么解决这个问题?
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
msngX = X
msngY = Y
End If
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
Picture1.Line (msngX, msngY)-(X, Y), , B
Picture1.DrawMode = vbNotXorPen
Picture1.Line (msngX, msngY)-(X, Y), , B
End If
End Sub
在PictureBox上用鼠标作图,要求效果就象在设计时用shape在picturebox上放一个矩形一样。上述代码当鼠标移动时,会出现一个随鼠标变化的矩形,只要在mouseup事件中,画出这个矩形就可以了。问题是,当鼠标停止移动时而又没有释放按纽时,矩形的外框看不见,原因是mousemove中,最后总是使drawmode=vbnotxorpen,所以停止不动时,看不见外框,怎么解决这个问题?
Private Sub Form_Load()
Picture1.AutoRedraw = True
End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
msngX = X
msngY = Y
End If
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Cls
If Button = vbLeftButton Then
Picture1.Line (msngX, msngY)-(X, Y), , B
' Picture1.DrawMode = vbNotXorPen
Picture1.Line (msngX, msngY)-(X, Y), , B
End If
End Sub
我不是要用cls清掉来达到这样的效果,我用vbnotxorpen的意思很明显是不能破坏picturebox里的其它图形,用cls。晕,那我还用vbnotxorpen干什么!