How to receive MouseUp event when mouse is over the TextBox?
-
Tuesday, April 22, 2008 6:03 PM
Answers
-
Tuesday, April 22, 2008 9:22 PM
Why do you want this?
The MouseUp event of the TextBox control is not wired on the CF. The event is hidden in Visual Studio, but even when you cast the TextBox Control to a Control and attach a EventHandler to the event it will not fire:
Code Snippetprivate void Form1_Load(object sender, EventArgs e)
{
Control c = this.textBox1;
c.MouseUp += new MouseEventHandler(c_MouseUp);
}
void c_MouseUp(object sender, MouseEventArgs e)
{
MessageBox.Show("I have no MouseUp event!");
}
I think the only way to achieve this is by some lowlevel unmanaged voodoo. Probably extending the (TextBox) Window messageloop and checking for the correct messages.
This raises the question: is it really neccesery and worth the crossing into the spooky world of unmanaged code, or are there alternative ways to implement your userinterface?
Greetings.
-
Thursday, April 24, 2008 8:42 AMModerator
Hi, Anatoliy
The KeyUp event is not implemented for a TextBox, because the event is not usually used by the control. However you can extend its abilities by subclassing the control, as explained in the following articles:
Subclassing controls in .NETCF 2.0, part 1
http://blogs.msdn.com/netcfteam/archive/2005/05/20/420551.aspx
Subclassing controls in .NETCF 2.0, part 2http://blogs.msdn.com/netcfteam/archive/2005/05/23/421143.aspx
Best Regards
Chunsheng Tang
All Replies
-
Tuesday, April 22, 2008 9:22 PM
Why do you want this?
The MouseUp event of the TextBox control is not wired on the CF. The event is hidden in Visual Studio, but even when you cast the TextBox Control to a Control and attach a EventHandler to the event it will not fire:
Code Snippetprivate void Form1_Load(object sender, EventArgs e)
{
Control c = this.textBox1;
c.MouseUp += new MouseEventHandler(c_MouseUp);
}
void c_MouseUp(object sender, MouseEventArgs e)
{
MessageBox.Show("I have no MouseUp event!");
}
I think the only way to achieve this is by some lowlevel unmanaged voodoo. Probably extending the (TextBox) Window messageloop and checking for the correct messages.
This raises the question: is it really neccesery and worth the crossing into the spooky world of unmanaged code, or are there alternative ways to implement your userinterface?
Greetings.
-
Thursday, April 24, 2008 8:42 AMModerator
Hi, Anatoliy
The KeyUp event is not implemented for a TextBox, because the event is not usually used by the control. However you can extend its abilities by subclassing the control, as explained in the following articles:
Subclassing controls in .NETCF 2.0, part 1
http://blogs.msdn.com/netcfteam/archive/2005/05/20/420551.aspx
Subclassing controls in .NETCF 2.0, part 2http://blogs.msdn.com/netcfteam/archive/2005/05/23/421143.aspx
Best Regards
Chunsheng Tang
-
Thursday, April 24, 2008 6:27 PMThanks Peter, Tang!
I needed control, that displays text and receives events from stylus taps. I decided to use abilities of Graphics's methods to draw text and rectangle on the form. So, I can use mouse events of the form.

