How to Disable Mouse Scroll in DevExpress TextEdit Control

Dear Friends,
 
TextEdit is one of the most commonly used controls in DevExpress WinForms library since it resembles the default TextBox control. You can set the TextEdit's properties to allow restricted entries like only numeric numbers, only numbers with 2 decimal places, currency format etcetera using the DisplayFormat and EditFormat properties. If the control's property is set to accept only numeric values then at run time if you place the mouse on the TextEdit control and scroll the mouse wheel then you will see the values changing smoothly. This is a very good feature, but in some cases, we do not want this feature to be used by the end-users. This article will explain how to disable MouseScrolling on the TextEdit control.
 
To disable mouse scrolling of the TextEdit control, we will handle the Spin Event of the control. This event is fired whenever the mouse wheel is scrolled on the control.
 
Let us use an example. We have a TextEdit control on the form and its name is txtNumeric.
 
Write the following code in your Form_Load() and then write the Spin() event handler as below.
 
VB.Net Version
 
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      AddHandler txtNumeric.Spin, AddressOf txtNumeric_Spin       
End Sub
 
Private Sub tbTextEdit_Spin(sender As Object, e As DevExpress.XtraEditors.Controls.SpinEventArgs)
        e.Handled = True
End Sub
 
C# Version
  1. private void Form1_Load(object sender, System.EventArgs e)  
  2. {  
  3.         txtNumeric.Spin += txtNumeric_Spin;  
  4. }  
  5.    
  6. private void tbTextEdit_Spin(object sender, DevExpress.XtraEditors.Controls.SpinEventArgs e)  
  7. {  
  8.         e.Handled = true;  

You're done. Run your application and try scrolling the mouse by focusing on the control. You won't be able to.
 
Hope you like this article. Please let me know your thoughts via comments.


Rebin Infotech
Think. Innovate. Grow.