ListViewInsertionMark.AppearsAfterItem Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee wordt een waarde opgehaald of ingesteld die aangeeft of de invoegmarkering rechts van het item wordt weergegeven met de index die door de Index eigenschap is opgegeven.
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
Waarde van eigenschap
true als de invoegmarkering rechts van het item wordt weergegeven met de index die is opgegeven door de Index eigenschap; falseanders. De standaardwaarde is false.
Voorbeelden
In het volgende codevoorbeeld ziet u hoe u de ListView functie voor het invoegen van markeringen gebruikt en het opnieuw ordenen van items met slepen en neerzetten implementeert met behulp van de standaardsleepgebeurtenissen. De positie van de invoegmarkering wordt bijgewerkt in een handler voor de Control.DragOver gebeurtenis. In deze handler wordt de positie van de muisaanwijzer vergeleken met het middelpunt van het dichtstbijzijnde item en wordt het resultaat gebruikt om te bepalen of de invoegmarkering links of rechts van het item wordt weergegeven.
Zie het overzichtsonderwerp voor het ListViewInsertionMark volledige voorbeeld.
// 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
Opmerkingen
Met NearestIndex de methode kunt u het item het dichtst bij de muisaanwijzer vinden, maar u moet uw eigen berekeningen uitvoeren om te bepalen of de invoegmarkering vóór of na dit item moet worden weergegeven.
Voer de volgende stappen uit om de waarde te berekenen die nodig is voor de AppearsAfterItem eigenschap:
Gebruik de NearestIndex methode om de index op te halen van het item dat zich het dichtst bij de muiswijzer bevindt.
Geef de indexwaarde door aan de ListView.GetItemRect methode om de begrenzingsrechthoek van het item op te halen.
Als de muis aanwijzer zich links van het middelpunt van de begrenzingsrechthoek bevindt, stelt u de eigenschap AppearsAfterItemin op ; anders stelt u
falsedezetruein op .
Zie het ListViewInsertionMark naslagonderwerp overzicht voor meer informatie.