C#ListView 마우스 휠 스크롤 없이커스
문제
내가 만드는 데 적용으로 목록을 설정하도록 자세하게 여러 가지 열을 표시할 수 있습니다.
고 싶은데 이에 대한 목록을 스크롤 마우스를 통해 제어하고 사용자는 사용 마우스 휠 스크롤.지금 스크롤는 경우에만 발생 ListView 포커스가 있습니다.
어떻게 만들 수 있습니 ListView 스크롤되지 않는 경우에도해야에 초점을 맞춥니까?
해결책
당신은 일반적으로 마우스를 얻/키보 이벤트 창 또는 통제가 있을 때 초점입니다.를 보시려면 그들에게 초점 없이 다음을 넣어하는 장소에서 낮은 수준이다.
다른 팁
"간단한"고 작업 솔루션:
public class FormContainingListView : Form, IMessageFilter
{
public FormContainingListView()
{
// ...
Application.AddMessageFilter(this);
}
#region mouse wheel without focus
// P/Invoke declarations
[DllImport("user32.dll")]
private static extern IntPtr WindowFromPoint(Point pt);
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == 0x20a)
{
// WM_MOUSEWHEEL, find the control at screen position m.LParam
Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16);
IntPtr hWnd = WindowFromPoint(pos);
if (hWnd != IntPtr.Zero && hWnd != m.HWnd && System.Windows.Forms.Control.FromHandle(hWnd) != null)
{
SendMessage(hWnd, m.Msg, m.WParam, m.LParam);
return true;
}
}
return false;
}
#endregion
}
제휴하지 않습니다 StackOverflow