ListViewInsertionMark.AppearsAfterItem 속성

정의

삽입 표시가 Index 속성으로 지정된 인덱스에 있는 항목의 오른쪽에 나타나는지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool AppearsAfterItem { bool get(); void set(bool value); };
public bool AppearsAfterItem { get; set; }
member this.AppearsAfterItem : bool with get, set
Public Property AppearsAfterItem As Boolean

속성 값

삽입 표시가 Index 속성으로 지정된 인덱스에 있는 항목의 오른쪽에 나타나면 true이고, 그렇지 않으면 false입니다. 기본값은 false입니다.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 ListView 삽입 표시 기능 및 구현 항목 끌어서 놓기 재정렬 표준을 사용 하 여 끌기 이벤트입니다. 삽입 표시의 위치에 대 한 처리기에서 업데이트 되는 Control.DragOver 이벤트입니다. 이 처리기에서 가장 가까운 항목의 중간점 마우스 포인터의 위치를 비교 하 고 결과 삽입 표시가 항목의 오른쪽 또는 왼쪽에 표시 되는지 여부를 확인 하려면 사용 됩니다.

전체 예제를 참조 하세요.를 ListViewInsertionMark 개요 항목을 참조 합니다.

// Moves the insertion mark as the item is dragged.
void myListView_DragOver( Object^ /*sender*/, DragEventArgs^ e )
{
   // Retrieve the client coordinates of the mouse pointer.
   Point targetPoint = myListView->PointToClient( Point(e->X,e->Y) );

   // Retrieve the index of the item closest to the mouse pointer.
   int targetIndex = myListView->InsertionMark->NearestIndex( targetPoint );

   // Confirm that the mouse pointer is not over the dragged item.
   if ( targetIndex > -1 )
   {
      // Determine whether the mouse pointer is to the left or
      // the right of the midpoint of the closest item and set
      // the InsertionMark.AppearsAfterItem property accordingly.
      Rectangle itemBounds = myListView->GetItemRect( targetIndex );
      if ( targetPoint.X > itemBounds.Left + (itemBounds.Width / 2) )
      {
         myListView->InsertionMark->AppearsAfterItem = true;
      }
      else
      {
         myListView->InsertionMark->AppearsAfterItem = false;
      }
   }

   // Set the location of the insertion mark. If the mouse is
   // over the dragged item, the targetIndex value is -1 and
   // the insertion mark disappears.
   myListView->InsertionMark->Index = targetIndex;
}
// Moves the insertion mark as the item is dragged.
private void myListView_DragOver(object sender, DragEventArgs e)
{
    // Retrieve the client coordinates of the mouse pointer.
    Point targetPoint = 
        myListView.PointToClient(new Point(e.X, e.Y));

    // Retrieve the index of the item closest to the mouse pointer.
    int targetIndex = myListView.InsertionMark.NearestIndex(targetPoint);

    // Confirm that the mouse pointer is not over the dragged item.
    if (targetIndex > -1) 
    {
        // Determine whether the mouse pointer is to the left or
        // the right of the midpoint of the closest item and set
        // the InsertionMark.AppearsAfterItem property accordingly.
        Rectangle itemBounds = myListView.GetItemRect(targetIndex);
        if ( targetPoint.X > itemBounds.Left + (itemBounds.Width / 2) )
        {
            myListView.InsertionMark.AppearsAfterItem = true;
        }
        else
        {
            myListView.InsertionMark.AppearsAfterItem = false;
        }
    }

    // Set the location of the insertion mark. If the mouse is
    // over the dragged item, the targetIndex value is -1 and
    // the insertion mark disappears.
    myListView.InsertionMark.Index = targetIndex;
}
' Moves the insertion mark as the item is dragged.
Private Sub myListView_DragOver(sender As Object, e As DragEventArgs)
    ' Retrieve the client coordinates of the mouse pointer.
    Dim targetPoint As Point = myListView.PointToClient(New Point(e.X, e.Y))
    
    ' Retrieve the index of the item closest to the mouse pointer.
    Dim targetIndex As Integer = _
        myListView.InsertionMark.NearestIndex(targetPoint)
    
    ' Confirm that the mouse pointer is not over the dragged item.
    If targetIndex > -1 Then
        ' Determine whether the mouse pointer is to the left or
        ' the right of the midpoint of the closest item and set
        ' the InsertionMark.AppearsAfterItem property accordingly.
        Dim itemBounds As Rectangle = myListView.GetItemRect(targetIndex)
        If targetPoint.X > itemBounds.Left + (itemBounds.Width / 2) Then
            myListView.InsertionMark.AppearsAfterItem = True
        Else
            myListView.InsertionMark.AppearsAfterItem = False
        End If
    End If
    
    ' Set the location of the insertion mark. If the mouse is
    ' over the dragged item, the targetIndex value is -1 and
    ' the insertion mark disappears.
    myListView.InsertionMark.Index = targetIndex
End Sub

설명

NearestIndex 메서드를 사용 하면 마우스 포인터를 가장 가까운 항목을 찾을 수 있지만이 항목 앞 또는 뒤에 삽입 표시가 표시 되어야 하는지를 결정 하기 위해 사용자 고유의 계산을 수행 해야 합니다.

에 필요한 값을 계산 하는 AppearsAfterItem 속성을 다음이 단계를 수행 합니다.

  1. 사용 된 NearestIndex 마우스 포인터에 대 한 가장 가까운 항목의 인덱스를 검색 하는 방법입니다.

  2. 인덱스 값을 전달 합니다 ListView.GetItemRect 항목의 경계 사각형을 검색 하는 방법입니다.

  3. 마우스 포인터의 경계 사각형의 중간점 왼쪽에 있는 경우, 설정 된 AppearsAfterItem 속성을 false이 고, 그렇지 않으면로 설정 true합니다.

자세한 내용은 참조는 ListViewInsertionMark 개요 항목을 참조 합니다.

적용 대상

추가 정보