是否有任何人/专家可以帮助我获取这些在mousemove事件中无法捕获的缺失值?
我项目的视频。 [View]
无论如何,我的想法是我们可以获得缺失值,例如
For Each i as even row index and j as odd row index
If i - j > 2
Do Until j = i
dgv.rows.insert()'code that will increase by +1
要确定行索引,我们可以说
If i Mod 2 = 0 Then
'even
Else
'Odd
End If
同样,这不是任何真正的代码。我只是想说明我的想法。
表格代码:
Public Class Form1
Dim drag As Boolean
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
If Not drag Then
Exit Sub
End If
dgv.Rows.Add((MousePosition.X - Me.Left - 8).ToString, (MousePosition.Y - Me.Top - 34).ToString)
End Sub
Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
drag = True
End Sub
Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
drag = False
Dim img As Bitmap = New Bitmap(Me.Width, Me.Height)
Dim gfx As Graphics = Graphics.FromImage(img)
For i As Integer = 0 To dgv.RowCount - 1
gfx.FillEllipse(Brushes.Black, Convert.ToInt32(dgv.Rows(i).Cells(0).Value), Convert.ToInt32(dgv.Rows(i).Cells(1).Value), 5, 5)
Next
PictureBox1.Image = img
End Sub
End Class
答案 0 :(得分:3)
好!
首先,感谢大家的意见(建议)。最后我找到了摆脱这个问题的解决方案。我没有找到这个解决方案,也没有找到任何类似的解决方案,除了用于绘制曲线我希望这个解决方案能够帮助未来的读者在绘制MouseMove事件时克服破折号。所以,在没有任何进一步讨论的情况下,让我为您提供解决方案。
解决方案代码:
Public Class Form2
Dim drag As Boolean
Dim img As Bitmap = New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim gfx As Graphics = Graphics.FromImage(img)
Dim imgPartial As Bitmap = New Bitmap(img)
Dim gfxPartial As Graphics = Graphics.FromImage(imgPartial)
Dim mouseX As Integer
Dim mouseY As Integer
Dim fixCurve() As Point
Dim redPen As New Pen(Color.Red, 3)
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove, Panel1.MouseMove
If drag Then
mouseX = (MousePosition.X - Me.Left - 8)
mouseY = (MousePosition.Y - Me.Top - 34)
gfxPartial.FillEllipse(Brushes.Red, MousePosition.X - Me.Left - 8, (MousePosition.Y - Me.Top - 34), 3, 3)
PictureBox1.Image = imgPartial
fixCurve(UBound(fixCurve)) = New Point(mouseX, mouseY)
ReDim Preserve fixCurve(UBound(fixCurve) + 1)
End If
End Sub
Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown, Panel1.MouseDown
drag = True
End Sub
Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp, Panel1.MouseUp
drag = False
'Here's the magic begin!!!
ReDim Preserve fixCurve(fixCurve.Length - 2)
gfx.DrawCurve(redPen, fixCurve)
PictureBox1.Image = img
gfxPartial.Clear(Color.White)
gfxPartial.DrawImage(img, New Point(0, 0))
ReDim fixCurve(0)
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load
ReDim fixCurve(0)
End Sub
End Class
优点:
此解决方案克服了DataGridView的使用,而是使用Arrays函数存储鼠标位置。