2012-05-10 3 views
2

나는 여러 UserControls와 스크롤 영역을 채우는 winforms 응용 프로그램이 있습니다. 내 질문에 어쨌든이 응용 프로그램보기가 표시되어있는 한 항상 마우스 휠 스크롤을 캡처 할 수 있습니까? 물론이 애플리케이션은 포커스를 위해 활동 중이다."항상"마우스 휠 이벤트와 스크롤 부모를 캡처합니까?

지금 마우스 휠 스크롤 작업을하기 위해 여물통을 스크롤 할 수있는 모든 컨트롤에 나타나는 스크롤 바를 클릭해야합니다. 이것은 무시하거나 건너 뛰고 싶습니다. 스크롤 할 수있는 영역에있는 이러한 UserControls 중 하나에서 텍스트 필드 중 하나를 클릭 할 수있게하려면 mousewheel로 스크롤하면이 UserControl이 스크롤하려고하지 않아야합니다. 그러나이 스크롤 가능합니다 이 UserControl이 다른 모든 UserControl과 함께 배치되는 영역 (부모)입니다. 기본 형태

답변

3

구현 IMessageFilter :

public partial class YourForm : Form, IMessageFilter 
{ 
    // Your code. 

    public bool PreFilterMessage (ref Message m) 
    { 
     if (m.Msg == 0x20A) 
     { 
      NativeMethods.SendMessage (controlToScroll.Handle , m.Msg , m.WParam , m.LParam); 
      return true; 
     } 
     return false; 
    } 
} 

는 그것의 생성자에서 다음 호출하여 메시지 필터로 양식을 등록합니다. 우수

internal class NativeMethods 
{ 
    [DllImport ("user32.dll" , CharSet = CharSet.Auto)] 
    public static extern IntPtr SendMessage (IntPtr hWnd , Int32 Msg , IntPtr wParam , IntPtr lParam); 
} 
+0

:

Application.AddMessageFilter (this); 

SendMessage 다음과 같은 서명이 있습니다! 고맙습니다. –

+0

'IMessageFilter'를 구현하는 것만으로는 충분하지 않은'WebBrowser' 컨트롤과 동일한 문제가있었습니다 : http://stackoverflow.com/questions/17228033/send-mousewheel-messages-to-system-windows-forms-webbrowser/17228034 # 17228034 특정 솔루션 –

관련 문제