如何填充无法在 MouseMove 事件中捕获的缺失值?
How do I fill the missing values which can't get captured on MouseMove event?
有没有人/专家可以帮助我获得这些在 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
应用截图:
好的!
首先感谢大家的意见(建议)。最后我找到了解决这个问题的方法。除了用于绘制曲线的 Microsoft 支持页面之外,我没有通过在网上搜索找到此解决方案或任何类似解决方案。我希望这个解决方案能帮助未来的读者在使用 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的功能来存储鼠标位置。
有没有人/专家可以帮助我获得这些在 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
应用截图:
好的!
首先感谢大家的意见(建议)。最后我找到了解决这个问题的方法。除了用于绘制曲线的 Microsoft 支持页面之外,我没有通过在网上搜索找到此解决方案或任何类似解决方案。我希望这个解决方案能帮助未来的读者在使用 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的功能来存储鼠标位置。