ListViewInsertionMark.AppearsAfterItem Propriedade

Definição

Recebe ou define um valor que indica se a marca de inserção aparece à direita do item com o índice especificado pela Index propriedade.

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 de Propriedade

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

Exemplos

O exemplo de código seguinte demonstra como usar a ListView funcionalidade de marcação de inserção e implementa a reordenação de itens por arrastar e largar usando os eventos padrão de arrastar. A posição da marca de inserção é atualizada num handler para o Control.DragOver evento. Neste manipulador, a posição do ponteiro do rato é 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 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

Observações

O NearestIndex método permite-lhe encontrar o item mais próximo do ponteiro do rato, mas deve fazer os 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 estes passos:

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

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

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

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

Aplica-se a

Ver também