C#ListViewコントロールは、マウスの動きとダブルバッファリングリストビューの強調表示項目ラインを実現します

C#ListViewコントロールは、マウスの動きとダブルバッファリングリストビューの強調表示項目ラインを実現します

1、リストビュークラス宣言、ダブルバッファリングのアカウント

class ListViewBuffered : System.Windows.Forms.ListView
    {
        public ListViewBuffered()
        {
            // 开启双缓冲
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);

            // Enable the OnNotifyMessage event so we get a chance to filter out 
            // Windows messages before they get to the form's WndProc
            this.SetStyle(ControlStyles.EnableNotifyMessage, true);
        }
    }

図2に示すように、リストビューコンポーネントは、変更を加えられた改変:オープンdesigner.csファイル、System.Windows.Forms.ListView Listivewからコンポーネントに対応の種類新たに設計され基づいて修正ListViewBuffered、2の合計と、AのWinForm新しいオブジェクトタイプのための部門は変数宣言です。

this.listView1 = new ProxyRedis.ListViewBuffered();

private ListViewBuffered listView1;

それは遅延を強調していないので、図3に示すように、ここでは、他のItemMouseHoverイベントで、関数にMouseMoveイベントを実現するためにイベントを追加するには、MouseMoveイベントを推奨しています。

private ListViewItem prItem;
private void listView1_MouseMove(object sender, MouseEventArgs e)
        {
           if (list.Items.Count <= 0)
                return;
            if (prItem != null)
            {
                prItem.BackColor = Color.White;
            }            
            prItem = list.GetItemAt(e.X, e.Y);
            if(prItem!=null)
                prItem.BackColor = Color.GreenYellow;
        }
公開された48元の記事 ウォンの賞賛3 ビュー20000 +

おすすめ

転載: blog.csdn.net/chscomfaner/article/details/103729892