<p>Is there any way to capture the MouseDown even from the .NET 2.0 TextBox control?
I know the inherited Control class has the event, but it's not exposed in TextBox.
Is there a way to override the event handler?</p>

<p>I also tried the OpenNETCF TextBox2 control which does have the MouseDown event exposed, but no matter what I do, it doesn't fire the handler.</p>

<p>Any suggestions?</p>

<hr>

<blockquote>
  <p>What kind of crazy mobile device do
  you have that has a mouse? :)</p>
</blockquote>

<p>Yes, windows mobile does not have an actual mouse, but you are mistaken that Windows Mobile .NET do not support the Mouse events.  A click or move on the screen is still considered a "Mouse" event.  It was done this way so that code could port over from full Windows easily.  And this is not a Windows Mobile specific issue.  The TextBox control on Windows does not have native mouse events either.  I just happened to be using Windows Mobile in this case.</p>

<p>Edit:  And on a side note...as Windows Mobile is built of the WindowsCE core which is often used for embedded desktop systems and Slim Terminal Services clients or "WinTerms" it has support for a hardware mouse and has for a long time.  Most devices just don't have the ports to plug one in.</p>

<hr>

<blockquote>
  <p>According to the .Net Framework, the
  MouseDown Event Handler on a TextBox
  is supported. What happens when you
  try to run the code?</p>
</blockquote>

<p>Actually, that's only there because it inherits it from "Control", as does <em>every</em> other Form control.  It is, however, overridden (and changed to private I believe) in the TextBox class.  So it will not show up in IntelliSense in Visual Studio.</p>

<p>However, you actually can write the code:</p>

<pre><code>textBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.textBox1_MouseDown);
</code></pre>

<p>and it will compile and run just fine, the only problem is that textBox1_MouseDown() will not be fired when you tap the TextBox control.  I assume this is because of the Event being overridden internally.  I don't even want to change what's happening on the event internally, I just want to add my own event handler to that event so I can fire some custom code as you could with any other event.</p>

[{'answer_id': 7799, 'author': 'GateKiller', 'author_id': 383, 'author_profile': 'https://Stackoverflow.com/users/383', 'pm_score': 0, 'selected': False, 'text': '<p>According to the .Net Framework, the <a href="http://www.csharpfriends.com/quickstart/aspplus/samples/classbrowser/cs/classbrowser.aspx?assembly=System.Windows.Forms,%20Version=1.0.5000.0,%20Culture=neutral,%20PublicKeyToken=b77a5c561934e089&amp;namespace=System.Windows.Forms&amp;class=TextBox" rel="nofollow noreferrer">MouseDown Event Handler on a TextBox</a> is supported. What happens when you try to run the code?</p>\n'}, {'answer_id': 7805, 'author': 'ageektrapped', 'author_id': 631, 'author_profile': 'https://Stackoverflow.com/users/631', 'pm_score': 0, 'selected': False, 'text': "<p>Fair enough. You probably know more than I do about Windows Mobile. :) I just started programming for it. But in regular WinForms, you can override the OnXxx event handler methods all you want. A quick look in Reflector with the CF shows that Control, TextBoxBase and TextBox don't prevent you from overriding the OnMouseDown event handler.</p>\n\n<p>Have you tried this?:</p>\n\n<pre><code>public class MyTextBox : TextBox\n{\n    public MyTextBox()\n    {\n    }\n\n    protected override void OnMouseDown(MouseEventArgs e)\n    {\n        //do something specific here\n        base.OnMouseDown(e);\n    }\n}\n</code></pre>\n"}, {'answer_id': 7840, 'author': 'ageektrapped', 'author_id': 631, 'author_profile': 'https://Stackoverflow.com/users/631', 'pm_score': 1, 'selected': True, 'text': '<p>Looks like you\'re right. Bummer. No MouseOver event.</p>\n<p>One of the fallbacks that always works with .NET, though, is P/Invoke. Someone already took the time to do this for the .NET CF TextBox. I found this on CodeProject:</p>\n<p><a href="http://www.codeproject.com/KB/cs/TextBox_subclassing.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/cs/TextBox_subclassing.aspx</a></p>\n<p>Hope this helps</p>\n'}, {'answer_id': 101931, 'author': 'dalelane', 'author_id': 477, 'author_profile': 'https://Stackoverflow.com/users/477', 'pm_score': 0, 'selected': False, 'text': "<p>is there an 'OnEnter' event that you could capture instead?</p>\n\n<p>it'd presumably also capture when you tab into the textbox as well as enter the text box by tapping/clicking on it, but if that isn't a problem, then this may be a more straightforward work-around</p>\n"}, {'answer_id': 1255291, 'author': 'Frank Razenberg', 'author_id': 153772, 'author_profile': 'https://Stackoverflow.com/users/153772', 'pm_score': 2, 'selected': False, 'text': "<p>I know this answer is way late, but hopefully it ends up being useful for someone who finds this. Also, I didn't entirely come up with it myself. I believe I originally found most of the info on the OpenNETCF boards, but what is typed below is extracted from one of my applications.</p>\n\n<p>You can get a mousedown event by implementing the OpenNETCF.Windows.Forms.IMessageFilter interface and attaching it to your application's message filter.</p>\n\n<pre>\n\nstatic class Program {\n    public static MouseUpDownFilter mudFilter = new MouseUpDownfilter();\n    public static void Main() {\n        Application2.AddMessageFilter(mudFilter);\n        Application2.Run(new MainForm());\n    }\n}\n\n</pre>\n\n<p>This is how you could implement the MouseUpDownFilter:</p>\n\n<pre>\n\npublic class MouseUpDownFilter : IMessageFilter {\n    List ControlList = new List();\n\n    public void WatchControl(Control buttonToWatch) {\n        ControlList.Add(buttonToWatch);\n    }\n\n    public event MouseEventHandler MouseUp;\n    public event MouseEventHandler MouseDown;\n\n    public bool PreFilterMessage(ref Microsoft.WindowsCE.Forms.Message m) {\n        const int WM_LBUTTONDOWN = 0x0201;\n        const int WM_LBUTTONUP = 0x0202;\n\n        // If the message code isn't one of the ones we're interested in\n        // then we can stop here\n        if (m.Msg != WM_LBUTTONDOWN && m.Msg != WM_LBUTTONDOWN) {\n            return false;\n        }\n\n        //  see if the control is a watched button\n        foreach (Control c in ControlList) {\n            if (m.HWnd == c.Handle) {\n                int i = (int)m.LParam;\n                int x = i & 0xFFFF;\n                int y = (i >> 16) & 0xFFFF;\n                MouseEventArgs args = new MouseEventArgs(MouseButtons.Left, 1, x, y, 0);\n\n                if (m.Msg == WM_LBUTTONDOWN)\n                    MouseDown(c, args);\n                else\n                    MouseUp(c, args);\n\n                // returning true means we've processed this message\n                return true;\n            }\n        }\n        return false;\n    }\n}\n\n</pre>\n\n<p>Now this MouseUpDownFilter will fire an MouseUp/MouseDown event when they occur on a watched  control, for example your textbox. To use this filter you add some watched controls and assign to the events it might fire in your form's load event:</p>\n\n<pre>\n\nprivate void MainForm_Load(object sender, EventArgs e) {\n    Program.mudFilter.WatchControl(this.textBox1);\n    Program.mudFilter.MouseDown += new MouseEventHandler(mudFilter_MouseDown);\n    Program.mudFilter.MouseUp += new MouseEventHandler(mudFilter_MouseUp);\n}\n\nvoid mudFilter_MouseDown(object sender, MouseEventArgs e) {\n    if (sender == textBox1) {\n        // do what you want to do in the textBox1 mouse down event :)\n    }\n\n}\n\n</pre>\n"}]
['https://Stackoverflow.com/questions/7719', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/194/']