2008-09-17 20 views
11

मैं एक सूची दृश्य के साथ WinForms ऐप को विस्तार से सेट कर रहा हूं ताकि कई कॉलम प्रदर्शित किए जा सकें।सी # सूची दृश्य के बिना माउस व्हील स्क्रॉल

मैं इस सूची को स्क्रॉल करने के लिए चाहता हूं जब माउस नियंत्रण में हो और उपयोगकर्ता माउस स्क्रोल व्हील का उपयोग करता हो। अभी, स्क्रॉलिंग केवल तब होती है जब ListView फोकस करता है।

जब मैं फोकस नहीं करता तब भी मैं सूची दृश्य स्क्रॉल कैसे बना सकता हूं?

उत्तर

3

आप आमतौर पर केवल खिड़की/कीबोर्ड घटनाओं को खिड़की या नियंत्रण पर प्राप्त करेंगे जब यह ध्यान केंद्रित करेगा। यदि आप उन्हें बिना फोकस के देखना चाहते हैं तो आपको निम्न-स्तरीय हुक डालना होगा।

Here is an example low level mouse hook

5

"सरल" और काम कर समाधान:

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 
} 
संबंधित मुद्दे