2014-07-23 3 views
0

저는 GDI +에서 새롭게 변경되었습니다. 누군가 내 일을 끝내도록 도와 줄 수 있습니까?라인 속성 변경

Private Sub DrawLines(ByVal g As Graphics) 
    For Each line As Line In Me.lines 
     g.DrawLine(Pens.White, line.Start, line.End) 
    Next line 
End Sub 

라인이 PictureBox를 객체에 그려진 :

내 코드입니다.

선이 그려지는 것은 개체가 될 것입니까? 그렇다면 클릭이나 다른 이벤트와 같은 일정을 사용하도록 설정하는 방법은 무엇입니까? 라인의 속성을 변경하는 방법?

Image은 라인 영역에 마우스 커서가 있으면 색상이 빨간색으로 바뀔 수 있습니다.

내 질문 : 어떻게해야합니까? 라인 영역 검색 및 라인 색 변경

누구나 간단한 논리를 줄 수 있습니까?

도움을 주시면 감사하겠습니다. 감사합니다

답변

1

나는 GDI +가 그런 선 개체를 제공한다고 생각하지 않지만 원하는 것을 할 수있는 GraphicPath 개체의 모음을 만들 수 있습니다. 클릭 이벤트를 확실히 감지 할 수 있습니다 (아래 그림 참조). 선의 가시 속성을 변경하는 것과 같이, 나는 Paint 메서드를 호출하고 다른 속성을 가진 Pen 개체를 사용해야한다고 생각합니다.

이 예제에서 DrawLines 메서드는 각 줄마다 GraphicsPath를 만들고 PictureBox_Paint를 호출하여 화면을 업데이트합니다. MyPen의 색상이나 너비를 변경하고 paint 메소드를 다시 호출하여 선을 다르게 다시 그릴 수 있습니다.

PictureBox1_MouseDown 메서드는 IsOutlineVisible을 사용하여 경로 중 하나가 클릭되었는지 확인합니다.

'Collection of paths to hold references to the "Lines" and a pen for drawing them 
Private MyPaths As New List(Of Drawing2D.GraphicsPath) 
Private MyPen As New Pen(Color.Red, 4) 


Private Sub DrawLines() 

    'Loop over the lines and add a path for each to the collection 
    For Each Ln As Line In Lines 
     Dim MyPath As New Drawing2D.GraphicsPath() 
     MyPath.AddLine(Ln.Start, Ln.End) 
     MyPaths.Add(MyPath) 
    Next 

    'Call method to draw the paths with the specified pen 
    PictureBox_Paint(Me, New System.Windows.Forms.PaintEventArgs(Me.PictureBox1.CreateGraphics, Me.PictureBox1.ClientRectangle)) 
End Sub 


Public Sub PictureBox_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint 

    For Each Pth As Drawing2D.GraphicsPath In MyPaths 
     e.Graphics.DrawPath(MyPen, Pth) 
    Next 
End Sub 


Private Sub PictureBox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown 

    'Create a Graphics object for PictureBox (needed for the IsOutlineVisible method) 
    Dim Gr As Graphics = Me.PictureBox1.CreateGraphics 

    'Loop over paths in collection and check if mouse click was on top of one 
    For Each Pth As Drawing2D.GraphicsPath In MyPaths 
     If Pth.IsOutlineVisible(e.Location.X, e.Location.Y, MyPen, Gr) Then 
      MessageBox.Show("Path was clicked", "Click") 
     End If 
    Next 
End Sub