标题:线太多了,怎么把多余的线去掉啊
只看楼主
sunchenhui90
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-1-12
 问题点数:0 回复次数:8 
线太多了,怎么把多余的线去掉啊
不用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
搜索更多相关主题的帖子: starty drawing cls False 
2013-01-13 14:44
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
得分:0 
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

2013-01-13 15:06
sunchenhui90
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-1-12
得分:0 
回复 2楼 lowxiong
还有个问题,当新线移动时会擦除以前的线,怎么办?
2013-01-13 15:50
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
得分:0 
两种方法,一种是使用一个数组,记住你画的线,每次移动线时都重画原来已经画好的线。另一种方法是你逐个画直线上的点,该点与背景点做异或算法,即可不擦出原来的线。
2013-01-13 16:31
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
得分:0 
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
2013-01-13 16:46
sunchenhui90
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-1-12
得分:0 
回复 5楼 lowxiong
这样又不能像橡皮筋那样拉伸了,怎么改成我原来那种不用一直按着鼠标的画法?
2013-01-13 19:31
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
得分:0 
'那你就把划线标志继续用上啊
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
2013-01-13 20:08
sunchenhui90
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-1-12
得分:0 
谢谢了
2013-01-13 20:14
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
得分:0 
'干脆帮你把取消划线的功能也做了,按鼠标右键即可取消你画的线,而按左键即可划线
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
2013-01-13 20:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-396456-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036020 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved