Hi,
I have a very simple app which is changing a panel backcolor by user input "txtCustomColor" I know how to use the text box keyDown event as you can see
private void txtCustomColo_KeyDown(object sender, KeyEventArgs e){if (e.KeyCode == Keys.Enter){panelCustom.BackColor = Color.(txtCustomColo.Text);}}
As you are fully aware this event need to press the Enter btn on the keyboard. Now my question is how I can handle the event after updating the text box and Mouse clicking out of the Textbox (Could be any where but txtCustomColor even on windows taskbar)
Best Regards,
VulpesPosted May 7, 2012, 10:11 AM
You could set the hook when the MouseLeave event fired and unset it when either the mouse was clicked or the MouseEnter event for the textbox fired. That would ensure that the hook callback method wasn't invoked when the mouse pointer was still within the bounds of the textbox.
There's a blog here which shows how to install a low-level mouse hook in C# and then detect when the mouse is clicked:
http://blogs.msdn.com/b/toub/archive/2006/05/03/589468.aspx
Behrouz HosseiniPosted May 7, 2012, 9:20 AM
Thanks for your comment but ,as far as I know, using the "Leave" event required having an other control and switching focus from the control to an other one. Is there any other method to do this without using another control? Like what we do in Visual Studio when we want to update control properties.Let's say for changing a "Button" Text we just change the "Text property" and if you do a Mouse click any where (Even outside of the Visual Studio) the button text will be updated.
Can you please let me know how to do this?
Thanks
VulpesPosted May 7, 2012, 5:11 AM
Incidentally, I'd have thought this line:
panelCustom.BackColor = Color.(txtCustomColo.Text);
should be:
panelCustom.BackColor = Color.FromName(txtCustomColo.Text);