03/06/2013 by Nitesh

How to Disable Mouse Scroll in DevExpress TextEdit Control

Dear Friends,

TextEdit is one of the most commonly used controls in DevExpress WinForms library as 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 etc using the DisplayFormat and EditFormat properties.  If the control’s property is set to accept only numeric values, at run time if you place the mouse on the TextEdit control and scroll the mouse wheel, 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 post will explain how can we disable MouseScrolling on the TextEdit control.

To disable the mouse scrolling on 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 take an example we have a TextEdit control on the form and its name is txtNumeric.

Write the below 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

private void Form1_Load(object sender, System.EventArgs e)
{
	txtNumeric.Spin += txtNumeric_Spin;
}

private void tbTextEdit_Spin(object sender, DevExpress.XtraEditors.Controls.SpinEventArgs e)
{
	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 post. Please let me know your thoughts via comments or contact me here.

#.Net#C##DevExpress#VB.Net#Winforms