Live Chat Icon For mobile
Live Chat Icon

How can I make a ReadOnly TextBox ignore the mousedowns so that you cannot scroll the text or set the cursor

Platform: WinForms| Category: TextBox

You can do this by deriving the TextBox, overriding the WndProc method and ignoring these mousedowns.

public class MyTextBox : TextBox
	protected override void WndProc(ref System.Windows.Forms.Message m)
		if(this.ReadOnly && (m.Msg ==  0xa1 || m.Msg == 0x201))
			return; //ignore it
		base.WndProc(ref m);
Public Class MyTextBox
	Inherits TextBox
	Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
		If Me.ReadOnly AndAlso(m.Msg = &HA1 OrElse m.Msg = &H201) Then 
			Return ’ignore it
		End If
	End Sub ’WndProc
End Class ’MyTextBox

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.