注册 登录
编程论坛 VB6论坛

线太多了,怎么把多余的线去掉啊

sunchenhui90 发布于 2013-01-13 14:44, 560 次点击
不用cls方法
Dim startx, starty As Single
Dim drawing As Boolean

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
    Form1.AutoRedraw = False
    startx = X
    starty = Y
    drawing = True
    End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If drawing Then
    Form1.Line (startx, starty)-(X, Y)
    Form1.MousePointer = 2
    End If
End Sub
8 回复
#2
lowxiong2013-01-13 15:06
Dim startx As Single, starty As Single
Dim drawing As Boolean
Dim oldx As Single, oldy As Single
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
    startx = X
    starty = Y
    oldx = X
    oldy = Y
    End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
    Form1.Line (startx, starty)-(oldx, oldy), Me.BackColor
    Form1.Line (startx, starty)-(X, Y), &HFF
    oldx = X
    oldy = Y
    Form1.MousePointer = 2
    End If
End Sub

#3
sunchenhui902013-01-13 15:50
回复 2楼 lowxiong
还有个问题,当新线移动时会擦除以前的线,怎么办?
#4
lowxiong2013-01-13 16:31
两种方法,一种是使用一个数组,记住你画的线,每次移动线时都重画原来已经画好的线。另一种方法是你逐个画直线上的点,该点与背景点做异或算法,即可不擦出原来的线。
#5
lowxiong2013-01-13 16:46
Dim startX As Single, startY As Single
Dim drawing As Boolean
Dim oldX As Single, oldY As Single
Dim arrayLine(100, 3) As Single, lineCount As Integer

Private Sub Form_Load()
  Dim i As Integer
  For i = 0 To 100
    arrayLine(i, 0) = -1
  Next
  lineCount = 0
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
    startX = X
    startY = Y
    oldX = X
    oldY = Y
    End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim i As Integer
    If Button = 1 Then
      Form1.MousePointer = 2
      Form1.Line (startX, startY)-(oldX, oldY), Me.BackColor
      For i = 0 To 100
        If arrayLine(i, 0) < 0 Then Exit For
        Form1.Line (arrayLine(i, 0), arrayLine(i, 1))-(arrayLine(i, 2), arrayLine(i, 3)), &HFF
      Next
      Form1.Line (startX, startY)-(X, Y), &HFF
      oldX = X
      oldY = Y
    End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  arrayLine(lineCount, 0) = startX
  arrayLine(lineCount, 1) = startY
  arrayLine(lineCount, 2) = oldX
  arrayLine(lineCount, 3) = oldY
  lineCount = lineCount + 1
End Sub
#6
sunchenhui902013-01-13 19:31
回复 5楼 lowxiong
这样又不能像橡皮筋那样拉伸了,怎么改成我原来那种不用一直按着鼠标的画法?
#7
lowxiong2013-01-13 20:08
'那你就把划线标志继续用上啊
Dim startX As Single, startY As Single
Dim drawing As Boolean
Dim oldX As Single, oldY As Single
Dim arrayLine(100, 3) As Single, lineCount As Integer

Private Sub Form_Load()
  Dim i As Integer
  For i = 0 To 100
    arrayLine(i, 0) = -1
  Next
  lineCount = 0
  drawing = False
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
      drawing = drawing Xor True
      If drawing Then
        Form1.MousePointer = 2
        startX = X
        startY = Y
        oldX = X
        oldY = Y
      Else
        Form1.MousePointer = 0
        arrayLine(lineCount, 0) = startX
        arrayLine(lineCount, 1) = startY
        arrayLine(lineCount, 2) = oldX
        arrayLine(lineCount, 3) = oldY
        lineCount = lineCount + 1
      End If
    End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim i As Integer
    If drawing Then
      Form1.Line (startX, startY)-(oldX, oldY), Me.BackColor
      For i = 0 To 100
        If arrayLine(i, 0) < 0 Then Exit For
        Form1.Line (arrayLine(i, 0), arrayLine(i, 1))-(arrayLine(i, 2), arrayLine(i, 3)), &HFF
      Next
      Form1.Line (startX, startY)-(X, Y), &HFF
      oldX = X
      oldY = Y
    End If
End Sub
#8
sunchenhui902013-01-13 20:14
谢谢了
#9
lowxiong2013-01-13 20:14
'干脆帮你把取消划线的功能也做了,按鼠标右键即可取消你画的线,而按左键即可划线
Dim startX As Single, startY As Single
Dim drawing As Boolean
Dim oldX As Single, oldY As Single
Dim arrayLine(100, 3) As Single, lineCount As Integer

Private Sub Form_Load()
  Dim i As Integer
  For i = 0 To 100
    arrayLine(i, 0) = -1
  Next
  lineCount = 0
  drawing = False
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
      drawing = drawing Xor True
      If drawing Then
        Form1.MousePointer = 2
        startX = X
        startY = Y
        oldX = X
        oldY = Y
      Else
        Form1.MousePointer = 0
        arrayLine(lineCount, 0) = startX
        arrayLine(lineCount, 1) = startY
        arrayLine(lineCount, 2) = oldX
        arrayLine(lineCount, 3) = oldY
        lineCount = lineCount + 1
      End If
    End If
    If Button = 2 And drawing Then
      Form1.Line (startX, startY)-(oldX, oldY), Me.BackColor
      drawing = False
      Form1.MousePointer = 0
    End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim i As Integer
    If drawing Then
      Form1.Line (startX, startY)-(oldX, oldY), Me.BackColor
      For i = 0 To 100
        If arrayLine(i, 0) < 0 Then Exit For
        Form1.Line (arrayLine(i, 0), arrayLine(i, 1))-(arrayLine(i, 2), arrayLine(i, 3)), &HFF
      Next
      Form1.Line (startX, startY)-(X, Y), &HFF
      oldX = X
      oldY = Y
    End If
End Sub
1