2016-06-20 1 views
0

VB.Net의 페인트 이벤트를 실험하고 있으며이 실험에서 입력 한 매개 변수에 따라 가로 또는 세로 반복을 만들고 싶습니다.) 선과 루프를 통과하여 해당 끝점 x 및 y를 충족시킵니다. 이 같은x 및 y 좌표를 지정하여 루핑을 통해 반복 선 만들기

뭔가 :

enter image description here

enter image description here

내가이 x와 y 시작점x와 y 끝 지점 함수가해야 주어집니다 달성하기 위해 노력하고있어 지정된 종점에 도달 할 때까지 지정된 시작점으로 시작하는 수직선 또는 수평선을 만듭니다.

paintevent를 사용하여 커브라인과 직선을 만들 수 있지만, 지금은 주어진 x 및 y 시작점과 끝점에서 루핑을 수행하는 방법에 대한 아이디어가 없습니다.

For x = xstart to xend Step Spacing 

Next 

경우 :

  • 은 Xstart = 귀하의 시작 지점
  • 선 사이
  • 하여 xend = 최종 지점
  • 간격 = 거리

답변

2

루프가 x/y 좌표를 반복합니다. 다음 예가 있습니다.

Public Class Form1 

    Private Enum Orientation 
     Vertical 
     Horizontal 
    End Enum 

    Protected Overrides Sub OnPaint(e As PaintEventArgs) 

     Dim orient As Orientation = Orientation.Vertical 
     Dim x As Integer = 100   'X Coord 
     Dim y As Integer = 100   'Y Coord 
     Dim count As Integer = 10  'Number of Lines to draw 
     Dim spacing As Integer = 5  'Spacing between lines in pixels 
     Dim length As Integer = 20  'Length of each line in pixels 
     Dim thickness As Integer = 3 'Thickness of each line in pixels 

     drawLines(x, y, orient, count, spacing, length, thickness, e.Graphics) 
    End Sub 

    Private Sub drawLines(x As Integer, y As Integer, orient As Orientation, count As Integer, spacing As Integer, length As Integer, thickness As Integer, g As Graphics) 

     'Create the Pen in a using block so it will be disposed. 
     'The code uses a red pen, you can use whatever color you want 
     Using p As New Pen(Brushes.Red, CSng(thickness)) 

      'Here we iterate either the x or y coordinate to draw each 
      'small segment. 
      For i As Integer = 0 To count - 1 
       If orient = Orientation.Horizontal Then 
        g.DrawLine(p, x + ((thickness + spacing) * i), y, x + ((thickness + spacing) * i), y + length) 
       Else 
        g.DrawLine(p, x, y + ((thickness + spacing) * i), x + length, y + ((thickness + spacing) * i)) 
       End If 
      Next 

     End Using 

    End Sub 
End Class 
+0

이것은 정말 대단합니다! 나는 그것이 그렇게 단순 할 것이라고 기대하지 않는다. –

0

당신이 뭔가를 시도 되세요