问题
Possible Duplicate:
How can I remove the selection border on a ListViewItem
I'm using the following code to make a Listview to use windows 7 native look and to prevent flickering.
Windows 7 Native Look for .NET ListView
http://geekswithblogs.net/CPound/archive/2006/02/27/70834.aspx
But I'm still getting a black dotted selection rectangle.


The question will be... How can I achieve the explorer selection rectangle?
Thank you so much for your help.
回答1:
Based on the comment in the link provided by AVIDeveloper.
While the ShowFocusCues itself didn't work, the WM_CHANGEUISTATE listed on that MSDN page led me to the right answer. By sending a WM_CHANGEUISTATE message with UISF_HIDEFOCUS I was able to get rid of the focus rectangle. – Telanor Apr 22 '10 at 17:11
I tried to find some information about this messages and eventualy saw this post: http://cboard.cprogramming.com/csharp-programming/128345-listview-remove-focuscues.html#post958690
So, we need to send the WM_CHANGEUISTATE message to the ListView in the constructor
SendMessage(Handle, 0x127, 0x10001, 0);
And we are only going to override the OnSelectedIndexChanged and OnEnter events.
protected override void OnSelectedIndexChanged(EventArgs e)
{
base.OnSelectedIndexChanged(e);
SendMessage(Handle, 0x127, 0x10001, 0);
}
protected override void OnEnter(EventArgs e)
{
base.OnEnter(e);
SendMessage(Handle, 0x127, 0x10001, 0);
}
Without overriding the OnEnter event, the same black dotted selection rectangle will appear when the ListView gets the focus.
I tried to explain the best I could since I'm not a fluent English speaker and I'm going to wait if someone has a better answer before accepting mine.
来源:https://stackoverflow.com/questions/9642281/listview-selection-rectangle