Share via


ListViewInsertionMark.AppearsAfterItem Propriedade

Definição

Obtém ou define um valor que indica se a marca de inserção aparece à direita do item com o índice especificado pela propriedade 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

Valor da propriedade

true se a marca de inserção aparecer à direita do item com o índice especificado pela Index propriedade ; caso contrário, false. O padrão é false.

Exemplos

O exemplo de código a seguir demonstra como usar o ListView recurso de marca de inserção e implementa a reordenação de item de arrastar e soltar usando os eventos de arrastar padrão. A posição da marca de inserção é atualizada em um manipulador para o Control.DragOver evento. Nesse manipulador, a posição do ponteiro do mouse é comparada ao ponto médio do item mais próximo e o resultado é usado para determinar se a marca de inserção aparece à esquerda ou à direita do item.

Para obter o exemplo completo, consulte o ListViewInsertionMark tópico de referência de visão geral.

// 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

Comentários

O NearestIndex método permite encontrar o item mais próximo do ponteiro do mouse, mas você deve fazer seus próprios cálculos para determinar se a marca de inserção deve aparecer antes ou depois desse item.

Para calcular o valor necessário para a AppearsAfterItem propriedade , siga estas etapas:

  1. Use o NearestIndex método para recuperar o índice do item mais próximo do ponteiro do mouse.

  2. Passe o valor de índice para o ListView.GetItemRect método para recuperar o retângulo delimitador do item.

  3. Se o ponteiro do mouse estiver localizado à esquerda do ponto médio do retângulo delimitador, defina a AppearsAfterItem propriedade como false; caso contrário, defina-a como true.

Para obter mais informações, consulte o ListViewInsertionMark tópico de referência de visão geral.

Aplica-se a

Confira também