[英]TextBox leave event in ContextMenuStrip not firing
I have a ContextMenuStrip containing two TextBoxes. 我有一个包含两个TextBoxes的ContextMenuStrip。
I want the validate the text inserted in a TextBox by using the TextBox.Leave event, but whenever I click outside the TextBox or the ContextMenuStrip, the event does not fire. 我想通过使用TextBox.Leave事件来验证插入到TextBox中的文本,但是每当我在TextBox或ContextMenuStrip之外单击时,该事件都不会触发。 The same for other events, like Validate, Enter etc. However, some events like MouseEnter or Click work.
对于其他事件,如Validate,Enter等,也是如此。但是,某些事件如MouseEnter或Click起作用。
Do you have any ideas? 你有什么想法?
Thank you! 谢谢!
I found a workaround using the LostFocus event on this post: 我在这篇文章中找到了使用LostFocus事件的解决方法:
https://social.msdn.microsoft.com/Forums/windows/en-US/79fe930b-880a-4e18-8e06-def459cec29d/how-to-detect-when-toolstriptextbox-loses-focus?forum=winforms https://social.msdn.microsoft.com/Forums/windows/en-US/79fe930b-880a-4e18-8e06-def459cec29d/how-to-detect-when-toolstriptextbox-loses-focus?forum=winforms
Just create LostFocus
event handler manually. 只需手动创建
LostFocus
事件处理程序。 NOTE- LostFocus
event is not showing in VS designer. 注意
LostFocus
事件未在VS设计器中显示。
public Form1()
{
InitializeComponent();
toolStripTextBox1.LostFocus += ToolStripTextBox1_LostFocus;
}
private void ToolStripTextBox1_LostFocus(object sender, EventArgs e)
{
//Your code!!!
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.