How can I remove the selection border on a ListViewItem

后端 未结 6 2178
粉色の甜心
粉色の甜心 2020-12-17 22:04

I\'m using SetWindowTheme and SendMessage to make a .net listview look like a vista style listview, but the .net control still has a dotted selection border around the selec

6条回答
  •  醉酒成梦
    2020-12-17 22:07

    Setting the HotTracking property to true hides the focus rectangle. This repro-ed the Explorer style on my Win7 machine:

    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    class MyListView : ListView {
      public MyListView() {
        this.HotTracking = true;
      }
      protected override void OnHandleCreated(EventArgs e) {
        base.OnHandleCreated(e);
        SetWindowTheme(this.Handle, "explorer", null);
      }
      [DllImport("uxtheme.dll", CharSet = CharSet.Auto)]
      public extern static int SetWindowTheme(IntPtr hWnd, string appname, string subidlist);
    }
    

    Beware that getting the items underlined is a side-effect.

提交回复
热议问题