2011-09-23 5 views
0

질문을 해결하는 데 도움이되는 사람이 있습니까? 그림을 필드로 어떻게 나눌 수 있습니까? 마우스를 클릭하면 특정 이벤트가 수행됩니다.SilverLight를 사용하여 그림을 필드로 나누는 방법

private void LayoutRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
    { 
     //if (!isDragging) 
     { 
      //creating of my user control element 
      NodePicture node = new NodePicture(); 
      node.Width = 100; 
      node.Height = 100; 

      //use cursor position as the center of the figure 
      Point point = e.GetPosition(this); 
      node.SetValue(Canvas.TopProperty, point.Y - node.Height/2); 
      node.SetValue(Canvas.LeftProperty, point.X - node.Width/2); 
      node.MouseLeftButtonDown += controlReletionshipsLine; 
      LayoutRoot.Children.Add(node); 
     } 
    } 

    private void controlReletionshipsLine(object sender, MouseButtonEventArgs e) 
    { 
     //creating parant element of node 
     ParentNode parentNode = new ParentNode(); 

     //creating connected element of the node 
     ConnectedNode connectedNode = new ConnectedNode(); 

     //creating node element 
     NodePicture node = (NodePicture)sender; 

     //getting the relative position of the element 
     Point point = e.GetPosition(this); 
+0

자세한 내용은 필수 항목입니다. 그림으로 무엇을 의미합니까 ?? –

+0

예를 들어 원으로 나눌 필요가 있습니다. @ Myles J – revolutionkpi

+0

html지도와 비슷합니까? – baalazamon

답변

3

당신은 클릭 한 위치 결정 "object를 기준으로"마우스 위치를 사용하여 수학적으로 객체를 분할 할 수 있습니다, 또는 당신이 1 색상 알파 채널 세트 각 다각형의 수를 오버레이 할 수 % (히트 테스트를 거칠 수 있지만 표시되지는 않음).

클릭 한 원의 1/4 만보고 싶다면 LeftMouseButtonDown 이벤트 args에서 GetPosition으로 전화를 걸어 컨트롤 자체를 매개 변수로 전달하십시오. 이렇게하면 Point 개체가 컨트롤의 왼쪽 위 모퉁이를 기준으로 위치를 갖습니다. 당신이 (controlReletionshipsLine에서) 나를 보내신 샘플 코드에서

private void ControlX_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
{ 
    // Get the relative position of the element 
    Point point = e.GetPosition(sender as UIElement); 

    if (point.X > control.Width/2) 
    { 
     if (point.Y > control.Height/2) 
     { 
      // You are in the bottom right quarter 
     } 
     else 
     { 
      // You are in the top right quarter 
     } 
    } 
    else 
    { 
     if (point.Y > control.Height/2) 
     { 
      // You are in the bottom left quarter 
     } 
     else 
     { 
      // You are in the top left quarter 
     } 
    } 
} 

당신은 :

// getting the relative position of the element 
Point point = e.GetPosition(this); 

이 있었어야

는 그런 다음에 그것이 분기 보는의 문제입니다 :

// getting the relative position of the element 
Point point = e.GetPosition(sender as UIElement); 
+0

나는 4 개의 버튼이있는 원의 그림이있다 : 원 안에 원저의 아래, 위, 왼쪽, 오른쪽. @ HiTech Magic – revolutionkpi

+0

만약 그것이 단지 4 분면이라면, 상대적인 마우스 위치가 위 또는 위인지를 확인하기 만하면됩니다 (위 아래, 위, 왼쪽, 오른쪽). 컨트롤 너비/높이의 절반 이하. 지금 내 대답을 업데이트 할 것입니다. –

+0

point.X는 상대 위치가 아니기 때문에 마우스 커서의 위치이므로이 경우에는 작동하지 않습니다. (if (point.Y> control.Height/2)) - 항상 true입니다. HiTech Magic – revolutionkpi

관련 문제