How can I remove the selection border on a ListViewItem

后端 未结 6 2135
粉色の甜心
粉色の甜心 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:06

    Telanors solution worked for me. Here's a slightly more self-contained version.

    using System;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    public class MyListView : ListView
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
    
        private const int WM_CHANGEUISTATE = 0x127;
        private const int UIS_SET = 1;
        private const int UISF_HIDEFOCUS = 0x1;
    
        public MyListView()
        {
            this.View = View.Details;
            this.FullRowSelect = true;
    
            // removes the ugly dotted line around focused item
            SendMessage(this.Handle, WM_CHANGEUISTATE, MakeLong(UIS_SET, UISF_HIDEFOCUS), 0);
        }
    
        private int MakeLong(int wLow, int wHigh)
        {
            int low = (int)IntLoWord(wLow);
            short high = IntLoWord(wHigh);
            int product = 0x10000 * (int)high;
            int mkLong = (int)(low | product);
            return mkLong;
        }
    
        private short IntLoWord(int word)
        {
            return (short)(word & short.MaxValue);
        }
    }
    

提交回复
热议问题