2010-11-24 3 views

답변

1

ToolStripComboBoxComboBox property이라는 이름으로 ComboBox 컨트롤을 유용하게 공개합니다. 이를 통해 ToolStripComboBox에 래핑되지 않은 속성, 메서드 및 이벤트에 액세스 할 수 있습니다.

그리고 표준 ComboBox 컨트롤은 콤보 상자에 포커스가있을 때 마우스 휠을 스크롤 할 때마다 발생하는 MouseWheel event을 노출합니다. 이 두 가지를 퍼팅

, 우리는 ToolStripComboBox 컨트롤의 내부 ComboBox 컨트롤의 MouseWheel 이벤트에 대한 처리기를 추가하고 기본 동작을 재정의 할 수 있습니다.

그래서, 당신은 ToolStripToolStripComboBox을 포함하는 형태를 가정하고, 다음과 같은 코드를 사용할 수 있습니다

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 

     //Attach a handler for the MouseWheel event 
     ToolStripComboBox1.ComboBox.MouseWheel += new MouseEventHandler(ToolStripComboBox_MouseWheel); 
    } 

    private void ToolStripComboBox_MouseWheel(object sender, MouseEventArgs e) 
    { 
     //Cast the MouseEventArgs to HandledMouseEventArgs 
     HandledMouseEventArgs mwe = (HandledMouseEventArgs)e; 

     //Indicate that this event was handled 
     //(prevents the event from being sent to its parent control) 
     mwe.Handled = true; 
    } 
} 

또는, 물론, 당신은 항상 기존 ToolStripComboBox 컨트롤을 서브 클래스 수 있으며, 위에 표시된 것과 같은 방식으로 행동을 재정의하십시오.

+0

너무 감사합니다 기대 작품 : 그냥 마우스 휠 핸들에 DroppedDown 상태를 프라하, 단! 완벽하게 작동해야합니다. – raz3r

+0

@ raz3r : 환영합니다. 내가 도울 수있어서 기쁩니다. 이것은 매우 좋은 질문이며, 빠른 Google 검색으로 답이 나오지 않습니다. –

+0

다시 한 번 감사드립니다. – raz3r

0

코디 그레이 (Cody Grey)가 제안한 것 외에도 콤보 박스를 떨어 뜨리면 휠 스콜 링이 작동하기를 원할 수도 있습니다.


    public class MyToolStripComboBox : ToolStripComboBox 
    { 
     public MyToolStripComboBox() 
     { 
      this.ComboBox.MouseWheel += new MouseEventHandler(ComboBox_MouseWheel); 
     } 

     void ComboBox_MouseWheel(object sender, MouseEventArgs e) 
     { 
      if (!this.ComboBox.DroppedDown) 
       ((HandledMouseEventArgs)e).Handled = true; 
     } 
    } 

스크롤이 선택을 변경하지 않는 휠 콤보 떨어졌다, 그래서 같이

관련 문제