ListViewInsertionMark.Color Property

Definition

Gets or sets the color of the insertion mark.

public:
 property System::Drawing::Color Color { System::Drawing::Color get(); void set(System::Drawing::Color value); };
public System.Drawing.Color Color { get; set; }
member this.Color : System.Drawing.Color with get, set
Public Property Color As Color

Property Value

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

Examples

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.

   ListViewInsertionMarkExample()
   {
      // Initialize myListView.
      myListView = gcnew ListView;
      myListView->Dock = DockStyle::Fill;
      myListView->View = View::LargeIcon;
      myListView->MultiSelect = false;
      myListView->ListViewItemSorter = gcnew 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 ( System::Environment::OSVersion->Version->Major > 5 || (System::Environment::OSVersion->Version->Major == 5 && System::Environment::OSVersion->Version->Minor >= 1) )
      {
         myListView->AllowDrop = true;
         myListView->ItemDrag += gcnew ItemDragEventHandler( this, &ListViewInsertionMarkExample::myListView_ItemDrag );
         myListView->DragEnter += gcnew DragEventHandler( this, &ListViewInsertionMarkExample::myListView_DragEnter );
         myListView->DragOver += gcnew DragEventHandler( this, &ListViewInsertionMarkExample::myListView_DragOver );
         myListView->DragLeave += gcnew EventHandler( this, &ListViewInsertionMarkExample::myListView_DragLeave );
         myListView->DragDrop += gcnew DragEventHandler( this, &ListViewInsertionMarkExample::myListView_DragDrop );
      }

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

private:
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);
}
Public Sub New()
    ' 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
        AddHandler myListView.ItemDrag, AddressOf myListView_ItemDrag
        AddHandler myListView.DragEnter, AddressOf myListView_DragEnter
        AddHandler myListView.DragOver, AddressOf myListView_DragOver
        AddHandler myListView.DragLeave, AddressOf myListView_DragLeave
        AddHandler myListView.DragDrop, AddressOf myListView_DragDrop
    End If 

    ' Initialize the form.
    Me.Text = "ListView Insertion Mark Example"
    Me.Controls.Add(myListView)
End Sub

Remarks

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

Applies to

See also