2017-09-24 3 views
0

mousemove 이벤트에서 캡처 할 수없는 누락 된 값을 얻을 수있는 전문가가 있습니까?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 

응용 프로그램의 스크린 샷 :
enter image description here

+0

누락 된 값은 무엇입니까? 여기에 전체 설명과 명확한 설명을 쓸 수있을 때 우리를 오프 사이트로 만들고 비디오를 보지 마십시오. – jmcilhinney

+1

좋아요, 코드로 업데이트 중입니다. 그러나 비디오를 제공하는 것이 문제를 설명하는 좋은 방법이라고 생각했습니다. –

+1

이제 확인할 수 있습니다. 나는 그 질문을 갱신했다. –

답변

3

좋아!

먼저 의견 (제안)에 대해 모두에게 감사드립니다. 마지막으로이 문제를 해결할 해결책을 찾았습니다. 필자는 그리기 곡선에 대한 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에의 사용을 극복하고 대신 마우스 위치를 저장하는 배열의 기능을 사용합니다.

관련 문제