ListViewInsertionMark.Color Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets the color of the insertion mark.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public Color Color { get; set; }

Property Value

Type: System.Drawing.Color

A Color value that represents the color of the insertion mark. The default value is the value of the ListView.ForeColor property.

Use this property to set the insertion mark color to a value other than the foreground color of the ListView control.

The following code example demonstrates how to use the ListView insertion mark feature and implements drag-and-drop item reordering using the standard drag events. The position of the insertion mark is updated in a handler for the Control.DragOver event. In this handler, the position of the mouse pointer is compared to the midpoint of the nearest item, and the result is used to determine whether the insertion mark appears to the left or the right of the item.

For the complete example, see the ListViewInsertionMark overview reference topic.

public ListViewInsertionMarkExample()
{
    // Initialize myListView.
    myListView = new ListView();
    myListView.Dock = DockStyle.Fill;
    myListView.View = View.LargeIcon;
    myListView.MultiSelect = false;
    myListView.ListViewItemSorter = new ListViewIndexComparer();

    // Initialize the insertion mark.
    myListView.InsertionMark.Color = Color.Green;

    // Add items to myListView.
    myListView.Items.Add("zero");
    myListView.Items.Add("one");
    myListView.Items.Add("two");
    myListView.Items.Add("three");
    myListView.Items.Add("four");
    myListView.Items.Add("five");

    // Initialize the drag-and-drop operation when running
    // under Windows XP or a later operating system.
    if (OSFeature.Feature.IsPresent(OSFeature.Themes))
    {
        myListView.AllowDrop = true;
        myListView.ItemDrag += new ItemDragEventHandler(myListView_ItemDrag);
        myListView.DragEnter += new DragEventHandler(myListView_DragEnter);
        myListView.DragOver += new DragEventHandler(myListView_DragOver);
        myListView.DragLeave += new EventHandler(myListView_DragLeave);
        myListView.DragDrop += new DragEventHandler(myListView_DragDrop);
    }

    // Initialize the form.
    this.Text = "ListView Insertion Mark Example";
    this.Controls.Add(myListView);
}

.NET Framework
Available since 2.0
Return to top
Show: